6Sorting in Linear Time.pdf - A-PDF Text Replace DEMO Purchase from www.A-PDF.com to remove the watermark Sorting in linear time 2 Decision-tree model A

6Sorting in Linear Time.pdf - A-PDF Text Replace DEMO...

This preview shows page 1 - 7 out of 22 pages.

Sorting in linear time A-PDF Text Replace DEMO: Purchase from to remove the watermark
2 Design And Analysis of Algorithms 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.
Design And Analysis of Algorithms 6) How many leaves does a decision tree have?
4 Design And Analysis of Algorithms Theorem : Any decision tree that sorts n elements has height (n lg n). Proof: There are n! possible outcomes. Thus there are at least n! leaves in the decision tree. A binary tree of height h has at most 2 h leaves. Thus, 2 h n!. We have h lg(n!) ≥Θ (n lg n). Note : Heapsort and mergesort are asymtotically optimal comparison sorts.
5 Design And Analysis of Algorithms Counting sort No comparison! Depends on an assumption about the members to be sorted. (eg. in the range 1..k) Time cost: O(k+n)
6 Design And Analysis of Algorithms COUNTING-SORT(A,B, k ) 1. for i 0 to k 2. do C[ i ] 0 3. for j 1 to length[A] 4. do C[A[ j ]] C[A[ j ]]+1 5. // C[ i ] contains number of elements equal to i .

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture