End of Term Review 2.2

End of Term Review 2.2 - Comparison Sort: Decision Trees...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Comparison Sort: Decision Trees For a 3-element array, there are 6 external nodes. For an n-element array, there are n ! external nodes. CSE 2011 Prof. J. Elder - 56 - Last Updated: 4/1/10 2:37 PM Comparison Sort To store n! external nodes, a decision tree must have a height of at least log n ! Worst-case time is equal to the height of the binary decision tree. Thus T (n) where log n ! = (log n !) n/2 n log i i =1 Thus T (n) log n / 2 (n log n) i =1 (n log n) Thus MergeSort & HeapSort are asymptotically optimal. CSE 2011 Prof. J. Elder - 57 - Last Updated: 4/1/10 2:37 PM Linear Sorts? Faster sorting may be possible if we can constrain the nature of the input. CSE 2011 Prof. J. Elder - 58 - Last Updated: 4/1/10 2:37 PM CountingSort Input: 1 0 0 1 3 1 1 3 1 0 2 1 0 1 1 2 2 1 0 1 Output: Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Value v: Location of next record with digit v. 0 0 1 5 23 14 17 Algorithm: Go through the records in order putting them where they go. CSE 2011 Prof. J. Elder - 59 - Last Updated: 4/1/10 2:37 PM CountingSort Input: 1 0 0 1 3 1 1 3 1 0 2 1 0 1 1 2 2 1 0 1 Output: 0 Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Value v: Location of next record with digit v. 0 0 1 6 23 14 17 Algorithm: Go through the records in order putting them where they go. CSE 2011 Prof. J. Elder - 60 - Last Updated: 4/1/10 2:37 PM ...
View Full Document

Page1 / 5

End of Term Review 2.2 - Comparison Sort: Decision Trees...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online