15-Heap___Priority_Queue

15-Heap___Priority_Queue - Max Heap Properties: - The value...

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

View Full Document Right Arrow Icon
Properties: - The value in each node is greater than all values in the node’s subtrees - Complete tree! (fills up from left to right) Max Heap Max Heap
Background image of page 1

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

View Full DocumentRight Arrow Icon
Properties: - The value in each node is less than all values in the node’s subtrees Min Heap Min Heap
Background image of page 2
1. Insert the new item in the next free position at the bottom of the heap (i.e. at the last row). 2. While the new item is not at the root and the new item is larger than its parent… - Swap the new item’s value with its parent value thus moving the new item up the heap. Inserting into Max Heap Inserting into Max Heap
Background image of page 3

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

View Full DocumentRight Arrow Icon
Inserting into Max Heap Inserting into Max Heap 10 6 3 2 7 9 Insert new element here 9 > 7 so swap the values Inserting new value 9 into the max heap
Background image of page 4
from the heap! 1. Remove the heap root and replace it with the rightmost item in the heap. 2. While the new root value has children and its value is smaller than the value of either of its children… - Swap the new item’s value with its
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

15-Heap___Priority_Queue - Max Heap Properties: - The value...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online