CS223-0214-HeapSort

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS223 Advanced Data Structures and Algorithms 2 Class Overview Class Overview d-Heap Sort using a heap Heapsort
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
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

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 Right Arrow Icon
Ask a homework question - tutors are online