This preview shows pages 1–3. Sign up to view the full content.
CMSC 132:
ObjectOriented Programming II
Department of Computer Science
University of Maryland, College Park
1
Reading
Read Section 8.5 in the Koffman text (Section
6.5 in the second edition)
Complete binary trees
A complete binary tree of height h is a tree
where
It's a perfect tree to level h1
The leaves at level h are as far left as possible
h = 2
h = 3
h = 1
3
Complete binary trees
not allowed
basic complete tree shape
4
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentHeaps
A heap is a binary tree with two key properties:
It's complete
The value in every node is less than or equal to the
values in its subtrees
A small example heap:
X
≤
Y
X
≤
Z
Y
X
Z
5
Examples
6
2
22
8
45
25
6
2
22
8
45
25
5
6
22
25
5
5
45
8
6
45
5
6
45
2
22
8
6
25
Heap properties
Heaps are balanced trees
Height = log
2
(n) =
O
(log(n))
The smallest element of a heap can always be
found easily
A heap could be organized to easily be able to
find the maximum value instead by ensuring
that the value at every node is larger than the
values in its subtrees
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 PADUAPEREZ

Click to edit the document details