Lecture_sorting_2p - 4/8/2008 Lecture 19: Sorting Intro...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
4/8/2008 1 Intro Bubble Sort Insertion Sort Lecture 19: Sorting Quick Sort Comparison Objective: sorting an array 12 4 Given an array of numbers in no particular orde 11 99 5 2 10 particular order 14 7 5 INPUT
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/8/2008 2 Objective: sorting an array 12 4 2 4 Given an array of numbers in no particular orde 11 99 5 2 10 5 5 7 10 particular order We want to produce an array with the same numbers, put in order 14 7 5 12 14 99 INPUT OUTPUT Objective: sorting an array 12 4 2 4 Given an array of numbers in no particular orde 99 5 2 10 5 5 7 10 particular order We want to produce an array with the same numbers, put in order There might be duplicate entries; that's OK 14 7 5 12 14 99 INPUT OUTPUT
Background image of page 2
4/8/2008 3 Bubble Sort 12 4 Start by looking at the first two numbers. Are they in order? 11 99 5 2 10 14 7 5 COMPARE Bubble Sort 12 4 Start by looking at the first two numbers. Are they in order? 4 12 99 5 2 10 If they aren't in order, swap them. 99 5 2 10 14 7 5 COMPARE 14 7 5 SWAP
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/8/2008 4 Bubble Sort 12 4 Start by looking at the first two numbers. Are they in order? 4 12 4 12 11 99 5 2 10 If they aren't in order, swap them. Now look at the next pair (2 nd and 3 rd numbers). Are they in order? 99 5 2 10 99 5 2 10 14 7 5 COMPARE 14 7 5 COMPARE 14 7 5 SWAP Bubble Sort 12 4 Start by looking at the first two numbers. Are they in order? 4 12 4 12 4 12 99 5 2 10 If they aren't in order, swap them. Now look at the next pair (2 nd and 3 rd numbers). Are they in order? If they are in order, 99 5 2 10 99 5 2 10 99 5 2 10 14 7 5 COMPARE don't do anything to them. 14 7 5 COMPARE 14 7 5 SWAP 14 7 5 DON'T SWAP
Background image of page 4
4/8/2008 5 Bubble Sort 12 4 Start by looking at the first two numbers. Are they in order? 4 12 4 12 4 12 4 12 11 99 5 2 10 If they aren't in order, swap them. Now look at the next pair (2 nd and 3 rd numbers). Are they in order? If they are in order, 99 5 2 10 99 5 2 10 99 5 2 10 99 5 2 10 14 7 5 COMPARE don't do anything to them. Now look at the 3 rd and 4 th numbers. .. 14 7 5 COMPARE 14 7 5 SWAP 14 7 5 DON'T SWAP 14 7 5 COMPARE Bubble Sort 12 4 From now on, we won't show the "compare" steps 4 12 4 12 4 12 4 12 99 5 2 10 compare steps. 99 5 2 10 99 5 2 10 99 5 2 10 99 5 2 10 14 7 5 COMPARE 14 7 5 SWAP 14 7 5 DON'T SWAP COMPARE COMPARE 14 7 5 14 7 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/8/2008 6 Bubble Sort From now on, we won't show the "compare" steps 4 12 4 12 compare steps. 11 99 5 2 10 99 5 2 10 14 7 5 SWAP 14 7 5 DON'T SWAP Bubble Sort From now on, we won't show the "compare" steps 4 12 4 12 4 12 Keep checking each pair of numbers, making swaps as needed. 99 5 2 10 99 5 2 10 99 5 2 10 14 7 5 SWAP 14 7 5 DON'T SWAP 14 7 5 SWAP
Background image of page 6
4/8/2008 7 Bubble Sort From now on, we won't show the "compare" steps 4 12 4 12 4 12 4 12 compare steps. Keep checking each pair of numbers, making swaps as needed.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/04/2009 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 42

Lecture_sorting_2p - 4/8/2008 Lecture 19: Sorting Intro...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online