Slippery Rock University Dr. Deborah Whitfield Go Browns!

Chapter 12: Heaps
Data Structures and Algorithms in Java
CpSc 374

Max Heap Tree

For a Min Heap Max Heaps are the Norm remove() TrickleDown(myRoot) insert (key) trickleUp(index)
while (index>0 && key(parent)< key(nn))
  swap(parent, nn)
   Update index and parent
  • Insert & Trickle Up
  • Insert Change a Priority
    Hidden cost of Change - O(N) Try find()
  • 96 - visit 7 of 19
  • 41 - visit 19 of 19
  • Discussion Sorting... yet again
  • Selection sort (recall)
  • A heap gives us the largest value in O(log n)
  • Heapsort
     
    for(j=0;j<N;j++) 
     	theHeap.insert(A[j]); 
    for(j=0;j<N;j++) 
         A[j] = theheap.remove(); 
    

    Practice

    WorkSheet

    Josh's question got me thinking ...
    Delete 111 and then 99 from this tree