22 Sorting Part 2

22 Sorting Part 2 - Sorting and order statistics part 2 O(n...

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

Sorting and order statistics, part 2 O(n) sorting and Randomized-select 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 08 Apr 2010

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

View Full Document
2 Announcements KevinBacon due tonight… Need a partner for Chess?
3 Last time…sorting Desirable sorting properties: in-place, adaptive, stable QuickSort n lg n sorting using partitioning items <= P items > P P

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

View Full Document
4 Suppose we pick a random pivot P Each item with probability 1/ n
5 Today: More sorting Finishing the O( n lg n ) sorts A lower bound BucketSort RadixSort Median-finding and order statistics

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

View Full Document
6 Sorting random inputs 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 on random array of 1 million integers, Java within Eclipse, 2005-era laptop running time (s) mergeSort randomizedQuickSort quickSort using a[left]
7 Sorting random inputs 0 5 10 15 20 25 1 3 5 7 9 11 13 15 input size (millions) running time (s) mergeSort randomizedQuickSort quickSort using a[left]

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

View Full Document
8 Sorting in the real world For small inputs, O( n 2 ) algorithms can beat quicksort Don’t sort small partitions Run InsertionSort afterward
9 Sorting random inputs 0 5 10 15 20 25 1 3 5 7 9 11 13 15 input size (millions) running time (s) mergeSort randomizedQuickSort partialQuickSort

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

View Full Document
10 Sorting in the real world, part 2 Carefully implement Partition/QuickSort Detect duplicates of your pivot items <= P items > P P items <= P P P P P P P P
11 The n lg n performance wall Heapsort, Mergesort, and Quicksort are all O( n lg n ) All comparison-based sorting algorithms are Ω ( n lg n ) An algorithm is comparison-based if it only asks questions of the sort “ Is a i a j ?

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.

{[ snackBarMessage ]}

Page1 / 37

22 Sorting Part 2 - Sorting and order statistics part 2 O(n...

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

View Full Document
Ask a homework question - tutors are online