Chapter 10. Trees. contents. Introduction definitions properties of trees Applications binary search trees Decision trees Prefix codes Tree traversal universal address systems inorder, preorder and postorder traversal infix, prefix and postfix notation – linearize(serialize) trees.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Chapter 10
Trees
x
y
==> X is the parent of Y
Def1: A tree is a connected undirected graph w/o simple circuits (cf: Forest)
Ex1: Family Tree:
Ex2:
tree
tree
has cycle
not connected
Theorm1:An undirected graph is a tree iff there is a unique simple path b/t any two of its vertices.
Pf:”=>”: T: any tree; x,y: two distinct vertices.
Since T is connected, by def., there is a path and hence a simple path a from x to y. Assume there is another simple path b from x to y.
Then by a theorem of ch 8 about simple circuit, there is a simple circuit in T.=> T is not a tree, a contradiction!
“<=“: There is a path b/t any two vertices ==> T is connected. Assume T contains a simple cycle containing x and y. (i.e., x a y b x
==> T contains two simple paths from x to y,
a contradiction.
f
f
g
g
f
g
d
d
d
b
b
b
e
e
e
a
a
a
c
c
c
T
With root a
With root c
A tree and Rooted Tree formed by designating two roots
{(u,v) ∈ V2{u,v}∈E and ∃a path r….uv in T}
f
g
d
b
e
a
c
Def: A rooted tree is an mary tree (m > 0) if every internal vertex has no more than m children.
a
c
b
g
d
f
e
h
i
k
j
l
m
Notes: 1. Like graphs, there is no standard terminology used to describe trees, rooted trees , ordered rooted trees
and binary trees.
2. Readers should
carefully check
meanings given to terms
dealing with trees whenever they occur.
CCC

C
Theorem 2: A tree with n ( n >0) vertices has exactly n1 edges.
Pf: Let T = (V,E) be a tree and choose a vertex r as the root. Now define the mapping g: EV {r} by
g(e) = v iff e={u,v} and v is the child of u.
Obviously g is 11 and onto. Hence E = V1.
11: if e1 = {u1,v}, e2 = {u2,v} with g(e1) = g(e2)=v =>
both u1 and u2 are the vertex appearing immediately before v in the unique simple path from r to v => u1 = u2. => if e1=e2
onto: v ∈ V – {r}, there is a unique simple path of length > 0 from r to v => there is a vertex u occurring immediately before v => g({u,v}) = v.
b
d
e
h
i
Theorem 3: A full mary tree with i internal vertices contains n = mi + 1 vertices.
Pf: Note: every edge in a tree T=(V,E,r) connects one parent(outdegree ) and one child (indegree).
=> the number of edges = E = Sv∈V #indegree(v)
[ = V1 : another proof of theorem 2 ]
= Sv∈V #outdegree(V) = Sv∈V #children(v)
= Sv∈Vall leaves #children(v)
 leaves have no children.
= Sv∈Vall leaves m = mi
 every internal vertex has m children.
=> V = mi + 1.
T: a full mary tree with n vertices, i internal vertices and l leaves. Then
pf: All are simple results of the following equations:
(1) n = mi + 1 (*, Theorem 3: mi = E = V1 =n1) and
(2) n = l + i (every vertex is either a leaf or an internal vertex)
1: i = (n1) /m and l = n  i =n – (n1)/m =[(m1)n+1]/m
2,3: Left as exercises.
Someone starts a chain letter. Each person receiving the letter either sends to 4 other people or stops sending letter. ==>
Sol: T=(V,E,r) where
V = all people receiving (and seeing) the letter
r = the person starting the game
E = {(u,v)  u sends a letter to v }
a
c
b
g
d
f
e
h
i
k
j
l
m
T=(V,E,r) : a tree, a: a vertex.
v in the tree?
tree if it is full and all
leaves have the same height
Def: A rooted mary tree of height h is called balanced if all leaves are at levels h or h1.
Example 11: Which of the rooted trees are balanced ?
T2
T1
T3
Theorem 5: There are at most mh leaves in an
mary tree T of height h.
Pf: By math ind on h.
Basis: h = 0 => T has only 1 = m0 node, which is a leaf.
Ind. case: Assume every mary tree of height h has leaves ≤ mh
=> mary tree T of height h+1 has at most m subtrees, each of height h =>
#leaves(T) = St’ is a subtree of T #leaves(T’)
≤ m x mh = m h+1.
Theorem 5’ : Every complete mary tree of height h has
mh leaves. Pf: Like Theorem 5.
1. If an mary tree of height h has l leaves, then h ≥ [logm l].
2. If the mary tree is full and balanced, then h =[logm l], where […] is the ceiling function.
Pf:1. By Theorem 5, l ≤ m h; hence h ≥ log m l. Since h is an integer, h ≥ [log m l].
2. ∵ balanced => h1 ≤ level of leaves ≤ h
∵ height = h => Some vertex is at level h.
=> mh1 < l ≤ m h.
=> h1< log m l ≤ h
=> log m l ≤ h < 1 + log m l
=> h = [log m l].