QuickSort_I_Dorr-351-Oct-18-2007

QuickSort_I_Dorr-351-Oct-18-2007 - code would probably be...

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

View Full Document Right Arrow Icon
This is another example of a “divide and conquer” algorithm. Step 1 (divide) Select a “pivot” value and logically partition the list into two sub-lists: L1: values less than the pivot L2: values greater than the pivot Your list is now: L1,pivot,L2 Step 2 (conquer) Sort L1 and L2 SORTED!
Background image of page 1

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

View Full DocumentRight Arrow Icon
Algorithm Let’s assume that our list L is held in an array and that we want to use as little extra space as possible. QuickSort(array L, int first, int last) { if (first<last) { pivotpos = Partition(L,first, last) QuickSort(L, first, pivotpos-1) QuickSort(L,pivotpos+1,last); } } NOTE: We would still need to write the partition algorithm. The easiest thing to
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: code would probably be to pick the last value in the list as the pivot and then partition based on that. There are many ways to implement the partition algorithm, but in terms of data comparisons, what should its runtime be? Start with T(0) = T(1) = 0 For the recurrence, what is: The worst case split? The best case split? The average/expected runtime? Lets return to the idea of expected values. Lets assume that every division situation is equally likely. If we let pos p represent the position of p, then we could represent the expected runtime as being:...
View Full Document

Page1 / 12

QuickSort_I_Dorr-351-Oct-18-2007 - code would probably be...

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

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