DOC PREVIEW
ASU CSE 310 - L08

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE310 Lecture 08: Lower-Bound For SortingTopics of this lectureComparison of sorting algorithmsSlide 3Slide 4Slide 5More Decision TreesHeight of a Binary TreeSlide 8An Alternative Proof of lg(n!) = (n lg(n))[email protected] Lecture 08:CSE310 Lecture 08:Lower-Bound For SortingLower-Bound For SortingGuoliang (Larry) XueDepartment of CSEArizona State Universityhttp://www.fulton.asu.edu/[email protected] of this lectureTopics of this lectureReview of worst-case running time of sorting algorithmsInsertion sortQuick sortMergesortComparison Based SortingDecision Tree ModelSorting Lower [email protected] of sorting algorithmsComparison of sorting algorithmsAlgorithm [best, average, worst]Insertion Sort [O(n), O(n2), O(n2)]Quicksort [O(n log n), O(n log n), O(n2)]Mergesort [O(n log n), O(n log n), O(n log n)][email protected]= Lower Bound for Sorting by Comparison =• sorting by comparison: we use only comparisons between elementsto gain order information about an input sequence <a1, a2, …, an>.That is, for any ai and aj , we perform one of the testsai = aj ?ai > aj ?ai < aj ?to determine their relative order.• sorting by comparison can be viewed abstractly in terms of decision [email protected]• decision tree: represents the comparisons performed by a sorting algorithm.- each internal node of the tree represents a comparisonbetween two elements ai and aj ( “is ai ≤aj ?” or “is ai > aj ?” )- each leaf of the tree represents a permutation of <a1, a2, …, an>.• The execution of the sorting (by comparison) algorithm corresponds to following the sequence of comparisons on the path from the root to a leaf of the decision [email protected] operating on elements <a1, a2, a3>a1 < a2?yes no a2 < a3? a1 < a3? no no yes yes< a1, a2, a3 > a1 < a3? < a2, a1, a3 > a2 < a3? yes no yes no< a1, a3, a2 > < a3, a1, a2 > < a2, a3, a1 > < a3, a2, a1 >• Each of the n! permutations of the elements must appear as a leaf of the tree, for the sorting algorithm to sort [email protected] Decision TreesMore Decision TreesAn example of a decision tree for using insertion sort to sort 4 elementsAn example of a decision tree for sorting 4 elements using quick sort.Any decision tree for sorting n elements must have at least n! leaf nodes. [email protected] of a Binary TreeHeight of a Binary TreeMinimum height of a binary treeA binary tree of height K has at most 2K+1-1 nodes.At most 2k-1 nodes at level k-1At most 2K+1-1 nodes total.As a result, the minimum height of a binary tree with n nodes is lg(n)[email protected]• the length of the longest path from the root to a leaf in the decision tree represents the worst-case number of comparisons the sorting algorithm performs.worst-case number of comparisons corresponds to heightof the decision tree of the algorithm• a binary tree with at least n! leaves has height at least log(n!). (why?)• we have that n! > (n/c)n (by Stirling’s approximation)Hence the height of a decision tree with at least n! leaves is> log (n!) > log [(n/c)n] = (n log n) Therefore (n log n) is a worst-case lower bound on the number ofcomparisons required by a sorting (by comparison) algorithm on asequence of n elements. (n log n) is a worst-case lower bound on the running time of any such [email protected] Alternative Proof of lg(n!) = An Alternative Proof of lg(n!) = (n lg(n))(n lg(n))n! = n*(n-1)*(n-1)*…*┌n/2┐*…*2*1 ≥ n*(n-1)*(n-1)*…*┌n/2┐ ≥(n/2)n/2.Therefore lg(n!) ≥lg(n/2)n/2=(n/2)lg(n/2)=(n lg(n))[email protected]Comparison based sorting has n*lg(n) as a lower bound.Decision Trees.The height of a decision tree corresponds to the worst-case time complexity of the corresponding sorting [email protected]The materials covered in this lecture can be found in Section 8.1.Work on exercises 8.1-1, 8.1-2,


View Full Document

ASU CSE 310 - L08

Documents in this Course
Load more
Download L08
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view L08 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view L08 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?