QuickSort_I_Dorr-351-Oct-18-2007

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

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

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!

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

View Full Document
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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
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? Let’s return to the idea of expected values. Let’s 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

## This note was uploaded on 01/13/2012 for the course CMSC 351 taught by Professor Staff during the Fall '11 term at University of Louisville.

### 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
Ask a homework question - tutors are online