05-Linear-Time-Sorting

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 ,
Background image of page 4
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 ,
Background image of page 5

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

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

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

View Full DocumentRight Arrow Icon
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.
Background image of page 8
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)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Algorithms L5.10 Lower bound for comparison sorting Corollary. Heapsort and merge sort are asymptotically optimal comparison sorting algorithms.
Background image of page 10
L5.11 Sorting in linear time Counting sort: No comparisons between elements. Input
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.

This note was uploaded on 04/29/2011 for the course IT 201 taught by Professor K.v.arya during the Spring '11 term at IIT Kanpur.

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 Right Arrow Icon
Ask a homework question - tutors are online