Download presentation
Presentation is loading. Please wait.
Published byPauline Sarah West Modified over 9 years ago
1
Sorting Algorithms Insertion Sort: Θ(n 2 ) Merge Sort:Θ(nlog(n)) Heap Sort:Θ(nlog(n)) We seem to be stuck at Θ(nlog(n)) Hypothesis: Every sorting algorithm requires Ω(nlog(n)) time.
2
Lower Bound Definitions Merge sort: Ω(nlog(n)) on every input Insertion sort: 1, 2, 3, 4,…, n-1, n O(n) time n, n-1, n-2, …, 2, 1 O(n 2 ) time Hypothesis: For every sorting algorithm A and every integer n, there is some input of length n on which A requires Ω(nlog(n)) time.
3
Proving Lower Bounds What if there is some absurd O(n) algorithm? E.g. Square every third element For every prime j, A[j] = 2^A[j] For every j, look up A[j]’th word in the August 2013 New York Times Etc.
4
Comparison sorting Want algorithms that work on any input e.g. insertion/merge/heap sort Think about sorting: uses comparisons. Comparison based sorting algorithm only relies on comparisons + moves Running time = Ω(# of comparisons)
5
New Hypothesis Every comparison-based sorting algorithm requires Ω(nlog(n)) comparisons in the worst case.
6
Required Comparisons O(nlog(n)) comparisons suffices merge sort, heap sort Trivial: need Ω(n/2) comparisons
7
New Hypothesis Every comparison-based sorting algorithm requires Ω(nlog(n)) comparisons in the worst case. Observation: Tree of height k has at most 2 k leaves.
8
Average Case Analysis Ω(nlog(n)) comparisons in worst case Merge sort: always Θ(nlog(n)) Insertion sort: sometimes Θ(n), sometimes Θ(n 2 ) Can we get the best of both? Sometimes Θ(nlog(n)), usually O(n)? NO: need Ω(nlog(n)) comparisons on average among all possible inputs.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.