Title: Trees
1Trees
A connected, acyclic, undirected graph T (V, E).
E V - 1
Minimally connected --- T is disconnected if any
edge is removed.
Maximally acyclic --- T contains a cycle if an
edge is added.
2Rooted Tree
root, ancestor
a
internal node (not a leaf)
parent
d
b
c
node (self)
sibling
e
f
leaf(no children)
g
h
child
child
j
i
e, i, k, g, h are leaves
descendent
k
3Subtree
root
A node and all of its descendents.
a
d
b
c
e
f
g
h
i
j
k
4Paths in a Tree
There exists a unique path from any node to any
of its descendents.
From a parent node to its child and
other descendents.
a
d
b
c
Path 1
Path 2
f
e
h
g
i
j
Path 1 a, b, f, j Path 2 d, i
5Depth and Height
depth 0
7
height 4
3
10
4
depth 1
node height 2
8
12
2
11
depth 2
1
depth 3
6
5
depth 4
9
6Degree
The number of children of a node x is called
the degree of x.
degree 3
7
3
10
4
8
12
2
11
degree 1
degree 0
1
6
5
9
7Binary Trees
Each node has at most two children.
Left child the child node on the left. Right
child the child node on the right.
A set of nodes T is a binary tree if
r
a) it is empty, or b) it consists of three
disjoint subsets 1) a root node
2) a left binary subtree 3) a
right binary subtree
a
e
b
c
f
d
right subtree
left subtree
8Full and Complete Binary Trees
Complete binary tree
Full binary tree
Each node is either a leaf or has degree exactly
2.
All leaves have the same depth and all internal
nodes have degree 2.
9Binary Tree Structure
a
b
c
f
e
g