Sorting1.7 - Execution Example (cont.) Recursive call, …,...

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: Execution Example (cont.) Recursive call, …, merge, merge CSE 2011 Prof. J. Elder - 36 - Last Updated: 4/1/10 11:16 AM Execution Example (cont.) Merge CSE 2011 Prof. J. Elder - 37 - Last Updated: 4/1/10 11:16 AM Analysis of Merge-Sort The height h of the merge-sort tree is O(log n) at each recursive call we divide in half the sequence, The overall amount or work done at the nodes of depth i is O(n) we partition and merge 2i sequences of size n/2i we make 2i+1 recursive calls Thus, the total running time of merge-sort is O(n log n) depth #seqs size 0 1 n 1 2 n/2 i 2i n/2i … … T (n) = 2T (n / 2) + O(n) … CSE 2011 Prof. J. Elder - 38 - Last Updated: 4/1/10 11:16 AM Heapsort Invented by Williams & Floyd in 1964 O(nlogn) worst case – like merge sort Sorts in place – like insertion sort Combines the best of both algorithms CSE 2011 Prof. J. Elder - 39 - Last Updated: 4/1/10 11:16 AM Selection Sort Largest i values are sorted on the right. Remaining values are off to the left. 3 5 1 4 < 6,7,8,9 2 Max is easier to find if a heap. CSE 2011 Prof. J. Elder - 40 - Last Updated: 4/1/10 11:16 AM ...
View Full Document

Page1 / 5

Sorting1.7 - Execution Example (cont.) Recursive call, …,...

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