{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec7 - EE 608 Computational Models and Methods Lecture 7...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
EE 608: Computational Models and Methods Lecture 7: Linear Sorts Read Chapter 8 of Introduction to Algorithms
Image of page 1

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

View Full Document Right Arrow Icon
Comparison Sort Algorithms How fast can we sort? Much depends on the assumptions one makes about how the sorting is accomplished. So far we have considered only algorithms that sort by comparing pairs of elements (i.e., Insertion-Sort , Merge-Sort , HeapSort , and Quick- Sort ). They are called comparison sorts . Any sort requires at least n - 1 comparisons, or it won’t have examined the input. However, all comparison sorts require Ω( n lg n ) comparisons to sort in the worst case. Can we achieve a sort that is faster than Ω( n lg n )? We assume that all elements are distinct while we are discussing the lower bound on comparison sorts. In this case, a i < a j , a i > a j , a i a j , a i a j provide equivalent information relative to ordering; hence, we use a i a j .
Image of page 2
Decision Trees A comparison sort can be viewed in terms of a decision tree , which represents the comparisons performed by the algorithm operating on an input of a certain size. a1:a2 > <= <= a1:a3 a2:a3 > <3,2,1> <2,1,3> <= a2:a3 a1:a3 <1,2,3> <1,3,2> <3,1,2> <2,3,1> > > > <= <=
Image of page 3

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

View Full Document Right Arrow Icon
Decision Trees continued There is a comparison tree for each input of size n . The leaves represent all possible permutations of the input array; hence, there are n ! leaves in the tree. Internal nodes represent comparisons between pairs of elements. The path from the root to a leaf shows the comparisons for arriving at the leaf’s permutation (an execution trace). The length of the longest path in the tree indicates its worst-case running time. Theorem 9.1: Any decision tree that sorts n elements has height Ω( n lg n ), (i.e., at least one path is that length).
Image of page 4
Complexity of Comparison Sorts Proof: (We ignore data movement, bookkeeping operations, etc.) The number of leaves in the decision tree is at least n !, or two permutations go to the same leaf. The number of leaves in a binary tree is 2 h , and: 2 h n ! h lg( n !) Recall Stirling’s approximation: n ! = 2 πn ( n e ) n (1 + Θ(1 /n )) > ( n e ) n , hence: h lg( n e ) n = n lg n - n lg e h = Ω( n lg n )
Image of page 5

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

View Full Document Right Arrow Icon
Decision Tree Questions 1. In a comparison sort decision tree, what do the leaves of the tree represent? How many leaves must there be in a decision tree sorting n elements? 2. In a comparison sort decision tree, what do the non-leaf nodes of the tree represent? 3. In a comparison sort decision tree, what do the edges of the tree represent?
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern