1 / 11

Heaps

Heaps. Full Binary Tree. A binary tree in which all the leaves are on the same level every nonleaf node has two children. Complete Binary Tree. A binary tree that is either full or full to the next-to-last level with leaves on last level as far left as possible. Heap. Two requirements

ross
Download Presentation

Heaps

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. Heaps

  2. Full Binary Tree • A binary tree in which • all the leaves are on the same level • every nonleaf node has two children

  3. Complete Binary Tree • A binary tree that is either • full or • full to the next-to-last level • with leaves on last level as far left as possible

  4. Heap • Two requirements • Shape • a complete binary tree • Order • each of elements contains a value • less (greater) than or equal value of either child

  5. Storing Tree in Array • Given parent is stored at position i • left child is in 2i +1 • right child is in 2i + 2 • parent of node i is at (i-1)/2

  6. Delete 15, Restart and Insert 20 • left child = 2i +1 • right child is in 2i + 2 • parent i is at (i-1)/2

  7. Demo • Priority queue may be implemented using heaps. • If we add or delete nodes, the heap would have to be adjusted. • http://www.ee.uwa.edu.au/~plsd210/ds/heaps.html#p_queue_anim

  8. Heap Sort Demo • http://gaigs.cmsc.lawrence.edu/cmsc34/AVClient.html • http://students.ceid.upatras.gr/~perisian/data_structure/HeapSort/heap_applet.html

  9. STL Heap Algorithms See HeapDemo.cpp

  10. STL priority_queue Operations See priorityqdemo.cpp

More Related