CS223-0214-HeapSort

# CS223-0214-HeapSort - Copy the elements back to the...

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

CS223 Advanced Data Structures and Algorithms 1 Heapsort and d-Heap Heapsort and d-Heap Neil Tang Neil Tang 02/14/2008 02/14/2008

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

View Full Document
CS223 Advanced Data Structures and Algorithms 2 Class Overview Class Overview d-Heap Sort using a heap Heapsort
CS223 Advanced Data Structures and Algorithms 3 d-Heap d-Heap A d-Heap is exactly like a binary heap except that all the nodes have d children.

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

View Full Document
CS223 Advanced Data Structures and Algorithms 4 d-Heap d-Heap Insertion takes O(log d N). deleteMin takes O(dlog d N) Computing the position of a child or the parent takes much more time unless d is a power of 2.
CS223 Advanced Data Structures and Algorithms 5 Sort using a Heap Sort using a Heap Perform N deleteMin operations. Every time, copy the deleted element (min) to a new array.

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

View Full Document

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

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

Unformatted text preview: Copy the elements back to the original array. Time complexity: NlogN. CS223 Advanced Data Structures and Algorithms 6 Heapsort Heapsort CS223 Advanced Data Structures and Algorithms 7 Heapsort Heapsort CS223 Advanced Data Structures and Algorithms 8 Heapsort Heapsort Build a (max)heap. Swap the first and the last element in the current heap. Update heap size and porcolateDown(1) Go back to the 2 nd step until the array is sorted. Time complexity (worst case): O(N+N*logN) = O(NlogN). Theorem: The average number of comparisons used to heapsort a random permutation of N distinct items is 2NlogN-O(NloglogN)....
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

CS223-0214-HeapSort - Copy the elements back to the...

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

View Full Document
Ask a homework question - tutors are online