SortingLowerBound-2

SortingLowerBound-2 - Every possible input permutation must...

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

(2,4) Trees 2/9/2006 12:42 AM 1 Sorting Lower Bound 1 Sorting Lower Bound Sorting Lower Bound 2 Comparison-Based Sorting (§ 4.4) Many sorting algorithms are comparison based. ± They sort by making comparisons between pairs of objects ± Examples: bubble-sort, selection-sort, insertion-sort, heap-sort, merge-sort, quick-sort, . .. Let us therefore derive a lower bound on the running time of any algorithm that uses comparisons to sort n elements, x 1 , x 2 , …, x n . Is x i < x j ? yes no

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

View Full Document
(2,4) Trees 2/9/2006 12:42 AM 2 Sorting Lower Bound 3 Counting Comparisons Let us just count comparisons then. Each possible run of the algorithm corresponds to a root-to-leaf path in a decision tree x i < x j ? x a < x b ? x m < x o ? x p < x q ? x e < x f ? x k < x l ? x c < x d ? Sorting Lower Bound 4 Decision Tree Height The height of this decision tree is a lower bound on the running time
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Every possible input permutation must lead to a separate leaf output. ± If not, some input …4…5… would have same output ordering as …5…4…, which would be wrong. Since there are n!=1*2*…*n leaves, the height is at least log (n!) minimum height (time) log ( n !) x i < x j ? x a < x b ? x m < x o ? x p < x q ? x e < x f ? x k < x l ? x c < x d ? n ! (2,4) Trees 2/9/2006 12:42 AM 3 Sorting Lower Bound 5 The Lower Bound Any comparison-based sorting algorithms takes at least log (n!) time Therefore, any such algorithm takes time at least That is, any comparison-based sorting algorithm must run in Ω (n log n) time. ). 2 / ( log ) 2 / ( 2 log ) ! ( log 2 n n n n n = ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ ≥...
View Full Document

This note was uploaded on 09/10/2009 for the course CS 401 taught by Professor Cs401 during the Spring '08 term at Illinois Tech.

Page1 / 3

SortingLowerBound-2 - Every possible input permutation must...

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

View Full Document
Ask a homework question - tutors are online