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:
Heaporder:
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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentLast 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
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '11
 Elder
 Data Structures, Binary heap, Prof. J., Prof. J. Elder

Click to edit the document details