Priority Queues and Heaps_Part_3

Priority Queues and Heaps_Part_3 - Min Heaps A min heap is...

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

View Full Document Right Arrow Icon
Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder - 11 - Min Heaps A min heap is a binary tree storing keys at its nodes and satisfying the following properties: Heap-order: for every internal node v other than the root key ( v ) key ( parent ( v )) (Almost) complete binary tree: let h be the height of the heap for i = 0, … , h ± 1, there are 2 i nodes of depth i at depth h r 1 the internal nodes are to the left of the external nodes Only the rightmost internal node may have a single child 2 6 5 7 9 The last node of a heap is the rightmost node of depth h
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last Updated: 06/02/12 8:32 PM CSE 2011 Prof. J. Elder - 12 - Height of a Heap Theorem: A heap storing n keys has height O (log n ) Proof: (we apply the complete binary tree property) Let h be the height of a heap storing n keys Since there are 2 i keys at depth i = 0, … , h ± 1 and at least one key at depth h , we have n 1 + 2 + 4 + + 2 h ± 1 + 1 Thus, n 2 h , i.e., h log n 1 2 2 h ± 1 1 keys 0 1 h ± 1 h depth
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Priority Queues and Heaps_Part_3 - Min Heaps A min heap is...

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

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