1 / 13

CISC220 Fall 2009 James Atlas

CISC220 Fall 2009 James Atlas. Nov 9: Heaps. Remaining Course Topics. Heaps Hashing Graphs. Heaps. Specialized Tree Often are Binary Heaps Satisfy Heap Property if B is a child node of A, then key(A) ≥ key(B) [in a Max-Heap]

cyard
Télécharger la présentation

CISC220 Fall 2009 James Atlas

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. CISC220Fall 2009James Atlas Nov 9: Heaps

  2. Remaining Course Topics • Heaps • Hashing • Graphs

  3. Heaps • Specialized Tree • Often are Binary Heaps • Satisfy Heap Property • if B is a child node of A, then key(A) ≥ key(B) [in a Max-Heap] • if B is a child node of A, then key(A)  key(B) [in a Min-Heap]

  4. Binary Max Heap

  5. Heap operations • insert: • adding a new key to the heap • delete-max or delete-min: • removing the root node • increase-key or decrease-key: • updating a key within a max- or min-heap, respectively • merge: • joining two heaps to form a valid new heap containing all the elements of both.

  6. Heap Insert • Add the element on the bottom level of the heap. • Compare the added element with its parent; if they are in the correct order, stop. • If not, swap the element with its parent and return to the previous step.

  7. Heap Insert (example) 1 2 3

  8. Heap Delete • Replace root with last element • Find max (or min) between root and children • Swap if child > root, recursively do find max on subtree now rooted at new child

  9. Heap Delete (example) 1 2

  10. Increase/Decrease Key?

  11. Implementations • Array? • Pointers?

  12. Operation Running Times

More Related