{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

05-Linear-Time-Sorting

# 05-Linear-Time-Sorting - Algorithms LECTURE 5 Sorting Lower...

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

Algorithms L5.1 Professor Ashok Subramanian L ECTURE 5 Sorting Lower Bounds Decision trees Linear-Time Sorting Counting sort Radix sort Appendix: Punched cards Algorithms

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

View Full Document
Algorithms L5.2 How fast can we sort? All the sorting algorithms we have seen so far are comparison sorts : only use comparisons to determine the relative order of elements. E.g ., insertion sort, merge sort, quicksort, heapsort. The best worst-case running time that we’ve seen for comparison sorting is O ( n lg n ) . Is O(n lg n) the best we can do? Decision trees can help us answer this question.
Algorithms L5.3 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a a . Sort a , a , …, a

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

View Full Document
Algorithms L5.4 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a a . 9 4 Sort a , a ,
Algorithms L5.5 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a a . 9 6 Sort a , a ,

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

View Full Document
Algorithms L5.6 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a a . 4 6 Sort a , a ,
Algorithms L5.7 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each leaf contains a permutation π(129 , π(229 ,…, π ( n ) to indicate that the ordering a a a has 4 6 9 Sort a , a ,

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

View Full Document
Algorithms L5.8 Decision-tree model A decision tree can model the execution of any comparison sort: One tree for each input size n . View the algorithm as splitting whenever it compares two elements. The tree contains the comparisons along all possible instruction traces. The running time of the algorithm = the length of the path taken. Worst-case running time = height of tree.
Algorithms L5.9 Lower bound for decision- tree sorting Theorem. Any decision tree that can sort n elements must have height ( n lg n ) . Proof. The tree must contain n ! leaves, since there are n ! possible permutations. A height- h binary tree has 2 leaves. Thus, n ! h lg( n !) ( lg is mono. increasing) lg (( n / e ) ) (Stirling’s formula)

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

View Full Document
Algorithms L5.10 Lower bound for comparison sorting Corollary. Heapsort and merge sort are asymptotically optimal comparison sorting algorithms.
L5.11 Sorting in linear time Counting sort: No comparisons between elements. Input

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 / 47

05-Linear-Time-Sorting - Algorithms LECTURE 5 Sorting Lower...

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

View Full Document
Ask a homework question - tutors are online