Sorting2.5 - Quick-Sort Running Time We can analyze the...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Quick-Sort Running Time We can analyze the running time of Quick-Sort using a recursion tree. At depth i of the tree, the problem is partitioned into 2i sub-problems. The running time will be determined by how balanced these partitions are. depth 0 1 … h CSE 2011 Prof. J. Elder - 76 - Last Updated: 4/1/10 11:16 AM Quick Sort 88 52 14 31 25 98 30 23 62 79 14 30 25 23 CSE 2011 Prof. J. Elder Let pivot be the first element in the list? 88 31 - 77 - 62 98 52 79 Last Updated: 4/1/10 11:16 AM Quick Sort 14,23,25,30,31,52,62,79,88,98 14 23,25,30,31,52,62,79,88,98 If the list is already sorted, then the list is worst case unbalanced. CSE 2011 Prof. J. Elder - 78 - Last Updated: 4/1/10 11:16 AM QuickSort: Choosing the Pivot Common choices are: random element middle element median of first, middle and last element CSE 2011 Prof. J. Elder - 79 - Last Updated: 4/1/10 11:16 AM Best-Case Running Time The best case for quick-sort occurs when each pivot partitions the array in half. Then there are O(log n) levels There is O(n) work at each level Thus total running time is O(n log n) depth time 0 1 n … i … log n CSE 2011 Prof. J. Elder n … n … n - 80 - Last Updated: 4/1/10 11:16 AM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

Sorting2.5 - Quick-Sort Running Time We can analyze the...

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

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