1 / 8

Heapsort and d-Heap Neil Tang 02/11/2010

Heapsort and d-Heap Neil Tang 02/11/2010. Class Overview. d-Heap Sort using a heap Heapsort. d-Heap. A d-Heap is exactly like a binary heap except that all the nodes have no more than d children. d-Heap. Insertion takes O(log d N). deleteMin takes O(dlog d N)

fallon
Download Presentation

Heapsort and d-Heap Neil Tang 02/11/2010

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Heapsort and d-HeapNeil Tang02/11/2010 CS223 Advanced Data Structures and Algorithms

  2. Class Overview • d-Heap • Sort using a heap • Heapsort CS223 Advanced Data Structures and Algorithms

  3. d-Heap • A d-Heap is exactly like a binary heap except that all the nodes have no more than d children. CS223 Advanced Data Structures and Algorithms

  4. d-Heap • Insertion takes O(logdN). • deleteMin takes O(dlogdN) • 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 • Perform N deleteMin operations. • Every time, copy the deleted element (min) to a new array. • Copy the elements back to the original array. • Time complexity: NlogN. CS223 Advanced Data Structures and Algorithms

  6. Heapsort CS223 Advanced Data Structures and Algorithms

  7. Heapsort CS223 Advanced Data Structures and Algorithms

  8. Heapsort • Build a (max)heap. • Swap the first and the last element in the current heap. • Update heap size and percolateDown(1) • Go back to the 2nd 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). CS223 Advanced Data Structures and Algorithms

More Related