Sequential Sorting A Lower Bound on Speed Chapter
Sequential Sorting A Lower Bound on Speed Chapter 35 Scott Orphan
Comparison or Sequential Sorting n n n Cannot inspect the values of the elements or gain order information in any other way. Data movement, control, etc. ignored. Uses only comparisons between elements. Decides between two elements which one is “bigger”.
Observations About Sorting Algorithms n n n Quicksort, Merge-sort, Insertion-sort, and Heapsort are comparison based. Why not Counting sort? ? All must perform at least O(n log n), in the worst case.
The Big Question: n Is there any comparison algorithm that can sort faster than O(n log n) in the worst case? The answer is NO!!
Proving The Lower Bound n n n Should be program and machine independent. Should not depend on which elements to compare. Uses an abstract way of modeling any possible comparison algorithm called a decision tree.
Conclusions n n A complete binary tree has the largest number of leaves possible for any binary tree of the same height. If N is the number of leaves of some binary tree of height h, then N ≤ 2 h. Thus: h ≥ log N.
The Decision Tree n n Is a binary tree. The execution of the comparison sorting algorithm corresponds to a path from the root to some leaf in the tree.
Decision Tree (cont. )
Proof of the Lower Bound n n Proof: Consider any sorting algorithm and integer n, and consider the resulting decision tree. T(n) is the number of comparisons in the worst case. By the definition of the decision tree, T(n) is the height of the tree.
Proof (cont. ) n n To prove the lower bound, we must prove that T(n)=O(n log n). The numbers could be presented in n! permutations (# of leaves in the decision tree). By the previous lemma, the height of the tree is at least log N = log n!. Hence, T(n) ≥ log n! The proof uses Stirling’s Formula for approximating n!.
Proof (cont. ) n n n N! ≤ 2 h H ≥ log(n!) H ≥ log(n/e)n ≥ n log n – n log e = O(n log n) // log of each side // Stirling’s approx. // Distribution // n log e is a cons. // so n log e is just // n + a coefficient
Conclusion n n Any comparison taking an n-item list as input must perform at least O(n log n) comparisons in the worst case. Any algorithm better than this must have the capability to make comparisons in parallel.
QUESTIONS? ?
- Slides: 15