notes13d

Repeatedly remove the largest item from the head and

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 1st),5(2nd),7,5(3rd)] [1,2,5(1st),5(2nd),5(3rd),7] Heap sort 1. Build a heap out of the data (list) O(nlogn) 2. Repeatedly remove the largest item from the head and insert into the output list O(nlogn) Example: [6,5,3,1,8,7,2,4] Build Heap 8 Heap : [8,6,7,4,5,3,2,1] (breadth first from diagram) [1,6,7,4,5,3,2,8] [7,6,3,4,5,1,2,8] [2,6,3,4,5,1,7,8] 6 [6,5,3,4,2,1,7,8] [5,4,3,1,2,6,7,8] … [1,2,3,4,5,6,7,8] Sorted order, heap is gone 3 4 5 1 7 2 Selection sort n 1. Repeatedly pick the largest item in the list and place it in the output Example:...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online