22 Sorting Part 2

22 Sorting Part 2 - Sorting and order statistics, part 2...

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

View Full Document Right Arrow Icon
Sorting and order statistics, part 2 O(n) sorting and Randomized-select 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 08 Apr 2010
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Announcements KevinBacon due tonight… Need a partner for Chess?
Background image of page 2
3 Last time…sorting Desirable sorting properties: in-place, adaptive, stable QuickSort n lg n sorting using partitioning items <= P items > P P
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 Suppose we pick a random pivot P Each item with probability 1/ n
Background image of page 4
5 Today: More sorting Finishing the O( n lg n ) sorts A lower bound BucketSort RadixSort Median-finding and order statistics
Background image of page 5

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

View Full DocumentRight Arrow Icon
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]
Background image of page 6
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]
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Sorting in the real world For small inputs, O( n 2 ) algorithms can beat quicksort Don’t sort small partitions Run InsertionSort afterward
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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 ?
Background image of page 11

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

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

Page1 / 37

22 Sorting Part 2 - Sorting and order statistics, part 2...

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