0% found this document useful (0 votes)
18 views107 pages

Trees

This document discusses different types of trees and tree traversal methods. It begins by defining what a tree is - an undirected, connected graph without cycles. It then covers rooted trees, m-ary trees, balanced trees, and binary trees. Different tree traversal methods are explained, including breadth-first, depth-first, in-order, pre-order and post-order traversals. Notations for representing expressions as trees are also introduced, such as infix, prefix and postfix notations. Various properties and theorems regarding trees are provided throughout with illustrative examples.

Uploaded by

jungjeyoo300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views107 pages

Trees

This document discusses different types of trees and tree traversal methods. It begins by defining what a tree is - an undirected, connected graph without cycles. It then covers rooted trees, m-ary trees, balanced trees, and binary trees. Different tree traversal methods are explained, including breadth-first, depth-first, in-order, pre-order and post-order traversals. Notations for representing expressions as trees are also introduced, such as infix, prefix and postfix notations. Various properties and theorems regarding trees are provided throughout with illustrative examples.

Uploaded by

jungjeyoo300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 107

Chapter 9: Trees

(Discrete Structure)
Chapter Outline
 9.1 Introduction to trees
 9.2 Rooted Trees
 9.3 M-ary and Balanced Trees
 9.4 Tree Traversal and Notation
 9.5 Spanning Trees
 9.6 Weighted Trees
Introduction of Trees

A Tree is a mathematical structure that is a


special kind of graph which has the ff. properties:
(1)it is undirected;(2)it is connected and (3) acyclic
,
Each edge connecting each pair of vertices is a
BRIDGE. On the other hand a FOREST is dis-point
union of trees meaning that forest is a set of trees.
We will denote T as Tree and F as Forest and also
the no. of components of a graph c(G).
Figure 9.1a Figure 9.1b Figure 9.1c

G1 G G3
2

Figure 9.1a,9.1b and 9.1c shows graphs G1, G2 & G3


respectively. Graph G1 is undirected & connected but
not acyclic, thus it is not a tree. Lastly, graph G3 is
undirected & acyclic but not connected, thus it is a
forest. Recall that a forest is a composition of trees;
observe that G3 has four trees of c(G)=4 which is
considered as a forest.
Theorem 9.1: Let T be a graph with v Vertices. Then the ff.
statements are equivalent.
(i) T is a Tree.
(ii) T contains no cycles and v - 1 edges.
(iii) T is connected and has v – 1 edges.
(iv) T is connected and every edge is a bridge
(v) Any vertices of T are connected by exactly one path
(vi)T contains no cycle and for any new edge e, the
graph T + e has exactly one cycle
-Theorem 9.2:Every nontrivial tree has at least two vertices
of degree 1
-Corollary 9.1:A forest F on v vertices has v – c(G) edges.
-Corollary 9.2:Any graph G on v vertices has at least v - c(G)
edges.
No. of No. of Graphs
Vertice edges
s 1 0
2 1
3 2
4 3

5 4

6 5

n n -1

Table 9.1: Some examples of trees with corresponding no. of


vertices and edges
A. Trees on chemical structure
Trees are also used representing chemical structures
such as methane (CH4),ethane(C2H6) & butane (C3H8).
The model molecules of hydrocarbons represent each
atom a vertex (Hydrogen-H and Carbon-C) and each
chemical bond by an edge.
Figure 9.2
B. Isomorphism
Since a tree isomorphism preserves root and
edge incidence, the level number of (1) a vertex
is a tree isomorphism invariant; (2) paths from
the root to the leaves is a tree isomorphism
invariant; (3) levels in a tree is a tree
isomorphism invariant & (4) leaf descendants of
a vertex are both tree isomorphism invariants.
-Theorem 9.3 Two trees are isomorphic if and
only if they have the same:

(i)number of levels & the same number


of vertices on each level
(ii) degree spectrum
(iii) degree spectrum at each level

-Theorem 9.4 There are 3 non-isomorphic trees


with 5 vehicles
Figur
e 9.3

Figur
e 9.4
Figure 9.5

Figur
e 9.6
Exercise
:
1.Draw a tree with 8 vertices such that 2 vertices
are of degree 1.
2.Draw a forest with 3 components and 9 vertices.
3.Draw the chemical structure of Benzene (C6H6).
4.Construct an Isomorphic tree using 6 vertices
5.Show the isomers of C4H4 of (Butane
and
isobidene).
Rooted Trees
A tree is Rooted tree if one vertex has been designated
the root, the term root usually refers to a top-most vertex
extends downward meaning each edge is simply directed
away from the root. On contrary a tree w/o root is called
ee
FFrigeuereTr9.7
.
Figure 9.8 IT Division Organization
Chart
A. Vertex Level and Height of a Tree
The Level (or depth) of a vertex is its distance
from the root.
The Height of the tree is the
number of vertices or edges traversed from
the most distant vertex. the root to get
Figure 9.11
B. Parent and Child of a Tree
In rooted tree, the Parent of a vertex is the vertex
connected to it on the path to the root (or a vertex
which closer to the root vertex and connected to
another vertex by a single bridge).
C. Sibling
A Sibling is a vertex which shares the same parent.
D. Descendants and ancestor
A Descendant is a vertex which is further away
from the root than some other vertex. The term
descendant is always in reference to another vertex.
An Ancestor is any vertex between a given vertex
and rooted including the root.
E. Terminal and Internal Vertices
A Terminal Vertex (or leaf) is a vertex with no
children (meaning, a vertex of degree one). On the
other hand an Internal Vertex (or branch
vertex) in a rooted tree is a vertex that has at least
one child.
F. Sub-tree
A Sub-tree is (usually) a smaller portion of a tree
starting at some specified vertex.
Figure 9.12
G. Ordered Rooted Tree
An Ordered rooted Tree is a rooted tree if all
groups of sibling vertices are assigned a relative
order (meaning the set of children of each
internal vertex is
ordered)
.
Figure 9.13
Exercise 9.2
Figure 9.14
Answer the ff. using figure 9.14
1. Height of the tree
2. Level of vertex x , p
3. The children on vertex i
4. The parent of vertex f
5. The siblings of vertex m
6. The ancestor of vertex j
7. The descendants of the h
8.The internal and terminal of
vertices
M-ary and Balanced Trees
A. M-ary Tree
If each vertex of a rooted tree T has most
m
children,
ee then we can say that T is an m-ary
Fitg.ru
re
9.15
Figure 9.16

Figure 9.17
Theorem 9.7: Given a full m-ary tree T or height
h. Then ha
s

Corollary 9.3: Let T be a complete m-ary tree of


height h having v vertices. Then
mh+ h+1
1 <v <m T
m-1
m-1
Example: The NBA League implements a new ruling of
single- elimination wherein a team is eliminated after a
single loss. If there are 30 teams to complete in the
tournament how many matches must be played to
determine the champion ?
Solution:
The number of teams represent the terminal vertices
t=30 and m-ary is binary since this denote the number
of teams to compete in each ball game, thus m = 2.
Substituting the values of t and m in our formula:
There will be 29 matches before
a champion will be declared.
B. Balanced
A tree of height h is balanced if all
terminal vertices (or
Fliegauvree9s)1
. a8ppear at levels h-1 or h.
C. Binary tree
A binary tree is an ordered 2-ary tree, if an
internal vertex has two children; they are
designated as either left child or right child. The
tree rooted at the left child of a vertex is called
Left9.19
Figure sub-tree.
Example : Write the left child-right
child array representation for the binary
tree in Figure 9.20
Solution:
Figure 9.20
Verte r a b c d e f
x

Left-child a - d f - - -

Right-child b c e - - - -
Theorem 9.8 The sum of the heights of the sub-trees in
complete Binary with v vertices and height h is v – h – L
Tree traversal and Notation
One of the most common operations performed on
trees are tree traversals. A Traversal is a process
visiting every vertex of an ordered rooted tree in a
systematic manner. Traversals are either breadth-first or
depth first.
A. Traversal / Search Trees
A breadth-first traversal is a strategy for traversing in
a tree, it begins at a root and the visiting each vertex,
starting from the lowest level and moving down by level,
visiting vertices from left to right.
While depth-first traversal is an algorithm for
traversing or searching a tree structure; it
starts
tree, at the root and visits as fast as possible along
each branch before backtracking.
Example 1: Given a tree in Figure 9.22,
the breadth-first traversal.
Determine
Solution: Figure 9.22
Breath-first traversal: r , a, b, c, d, e, f
The example clearly shows that adth-first
bre must traversal
Complete each level before proceed
the next level starting with theing to
root.
B. In-order , Pre-order , and Post-order
In-order Traversal of Tree T is done by the order of
L-P-R
meaning left child-parent-right child.

Pre-order Traversal of trees is done by the order of


P-L-R
meaning parent – left child – right child.

Post-order Traversal of Tree T is done by the order


of L-R-P
meaning left child- right child – parent.
Example: On figure 9.22 determine the in-
order , pre- order & post-order
Solution: Recall that the in-order we first
visit the left sub-tree
Then we visit the root and then the right sub- as
shown in figure 9.23. Figure
tree9.22
In-order : c, a, d, r, e, b, f
Pre-order : r, a, c, d, b, e,
f
Post-order : c, d, a, e, f, b, r
Figure 9.23
C. Infix, Prefix, and Postfix Notation
An Infix notation is a for of notation for symbolic
logic , arithmetic, and algebra. It is when operators
are written in-between their operands.
The Prefix notation (or Polish notation) introduce by
mathematician Jan Lukasiewcz in the 1920’s. It is
when is operators are written before their
operands.
The Postfix (or Reverse Polish notation) is a notation
when the operators are written after their
operands it was introduced by Arthur W. Burks,
Don W. Warren and Jesse B Wright in 1954
In all 3 notations to keep the meaning correct only
the operators have to be moved. The tree of the
expression a + b in figure 9.26 the infix, prefix, and
postfix notations are:
Figure 9.26
Infix Notation : a + b

Prefix Notation : + a b

Postfix Notation : a b
Example 4: Construct the binary tree of the given
expression
(a ^ b)*((c - d (d / e))+f and determine the
equivalent infix notation and postfix notation
equivalent.
Solution:
a. In expression (a ^ b)*((c - d (d / e))+f the main
operator is “*” (multiplication) which will serve as
the root of the binary tree. The left sub-tree will
contain (a^ b) expression, while the right sub-tree
will contain ((c-(d/e))+f) expression.
In the expression (a + b), a and b are siblings,
while “+” (addition) operator is their parent.
On the right sub-tree ((c-(d/e))+f) its main operator
is “+” which in turn can be divided into right and
left sub-trees for level 2. The left sub-tree is f
and the right sub-tree is the expression (c-(d/e)).
Applying the same approach for the right sub-tree (c-
(d/e)) for level 3, which contain a main operator of
“-” (subtraction).
Lastly, the expression (d/e), will be represented
where d is the left leaf, their parents is “/”
(division). Operator.
Figure 9.27 show the step by step procedure in
plotting the (a^b)*((c - d (d / e))+f in binary tree.
Figure 9.27
b. The infix of the expression (a^b)*((c-(d/e)+f)
is a^b*c-d/e+f, we only need to remove the
parenthesis.

c. The prefix of the expression (a^b)*((c-(d/e)+f)


is a^b*c-d/e+f) is (a^b)*((c-(d/e)+f) is a^b*c-
d=/e*+^f)ab=(^(ca(-bd*/(e(c)-+(df/)e))+f)
= *^ab((-cd/e)+f)
= *^ab(/-cde+f)
= *^ab+-c/def
d. The postfix of the expression (a^b)*((c-(d/e)
+f) is a^b*c-d/e+f) is (a^b)*((c-(d/e)+f) is
a^b*c- d/e+f)
= (a^b)* ((c-de/)+f)
= (a^b)* (cde/-+f)
= (a^b) cde/-f+*
= (a^b) ^cde/-f+*
Spanning Trees
A Spanning Tree of a graph is a sub graph which is a
tree and contains all vertices of the graph.
In the graphs T1, T2, T3, and T4 represent a spanning
tree for the graph G on the left. Observe that the
spanning tree is not unique and any connected graph
has at Fleg
i ausrteo9n.e28spanning tree
Theorem 9.11: A connected graph G has(at least) one
spanning
Tree
Theorem 9.12: Every graph has a spanning
v-2
forest.
Theorem 9.13: (Cayley’s Theorem) There
are v

labeled
trees with v
vertices.
Theorem 9.14: Given a spanning tree T
of G and an edge
e of G
which does not belong to T the
Example 1 : In figure 9.29 given a graph G we
can obtain a spanning forest like F1 and F2 as
shown below. We can obtain a number of
different forests in a given a graph as noted on
theorem 9.12.
Figure 9.29
Example 2:
Find the number of trees of the complete
spanning graph K3
Solution:
Using Cayley’s theorem where
Thus, there are 3 sub-trees for complete graph K3.
Graphically figure 9.30 shows 3 different sub-trees T1,
FiTg2u,raen9d3
. T03 of K3
b. Minimum Spanning Tree
The three knows personalities in the field of graph
theory, specifically on the spanning tree: Robert Clay
Prim , Joseph Bernard Kruskal and Edsger W.
Dejkstra.
Robert Clay Prim Developed the Prim’s
algorithm 1957 which is a greedy algorithm that
determines
a minimum spanning tree for
a connected
weighted
undirected graph. The
algorithm finds a
subset of
Joseph Bernard Kruskal an mathematician
that introduced the Kruskal’s Algorithm for
computing minimal spanning trees (MST) of a
weighted tree. Kruskal’s Algorithm first orders
the edges by weight and then proceeds
through the ordered list adding an edge to the
partial MST provided that adding the new edge
does not create a cycle.
Edsger W. Dijkstra a computer scientist who
conceived
The Dijkstra’s Algorithm.The algorithm is a graph
Search Algorithm that determines the single
source
shortest Path problem for graph producing a
shortest path Tree.
Example: Find the spanning tree T such that the sum of
the weights of the edges is the smallest possible
using Prim’s and Kruskal’s Algorithms.

Figure 9.30
Solution:
a. We will first evaluate the minimum
Spanning tree solution of the given tree
of figure 9.32 using Prim’s Algorithm
The Prim’s Algorithm computes the ff. Sequence of
partitions:
P0 = {(a),(b),(c),(d),(e),(f),(g)} Figure 9.33
P1 = {(a,c),(b),(d),(e),(f),(g )}
P2 = {(a,b,c),(d),(e),(f),(g) }
P3 = {(a,b,c,e),(d),(f),(g)}
P4 = {(a,b,c,d,e),(f),(g)}
P5 = {(a,b,c,d,e,g),(f)}
P6 = {(a,b,c,d,e,f,g)}
All the vertices already connected and thus we already
established the minimum spanning Tree. Figure 9.33
shows the spanning tree with a total weight of
3+6+7+3+2+8=29
b. This time we will determine the minimum
spanning tree solution using Kruskal’s
Algorithm.
The Kruskal’s Algorithm compute the ff. Sequence of
partitions:
P0 = {(a),(b),(c),(d),(e),(f),(g)} Figure 9.34
P1 = {(a),(b),(c),(d,g),(e),(f)}
P2 = {(a,c),(b),(d,g),(e),(f)}
P3 = {(a,c),(b),(d,e,g),(f)}
P4 = {(a,b,c,d,e),(f),(g)}
P5 = {(a,b,c,d,e,g),(f)}
P6 = {(a,b,c,d,e,f,g)}
After we already know established a tree we then
solve the total weight of the , minimum spanning
tree.
3+6+7+3+2+8=29
Theorem 9.15 : Let G be any weighted connected
graph. Each of Kruskal’s Algorithm and Prim’s
Algorithm yield a minimum spanning tree for G.
Theorem 9.16 : Let G be any weighted connected
graph and v a vertex of G Dijkstra’s Algorithm yields
a shortest path tree for G from v.

Figure 9.35
Enrichment Exercise:
1. Draw a forest F with c(G) = 3 and 8 vertices.
2. Construct a spanning tree of a cycle graph
C3 .
3. Find the number of spanning trees of the
complete graph K4 .
4. Determine the minimum spanning tree of
Figure 9.35 using Prim’s and Kruskal’s
Algorithms.
Weighted Trees
A. Weighted tree
We refer T a weighted tree if a nonnegative real
number is assigned to each terminal vertex.
This number is called weight of the terminal
vertices.
Example 1:
Consider the weighted tree on figure 9.36 and
figure 9.37; find an optimal binary tree
with weights 2,4,5,7,8,10.
Figure 9.36 Figure 9.37

Solution:
First we need to collect the given and apply the
summation of the weight of the rooted
tree.
b. Huffman Encoding trees
Computer store character data in binary from as
sequence of 1s and Os (bits), the usual approach to
used Fixed-
length codes wherein each symbol in the
message with the same number of bits.
The ASCII (American Standard Code for
Information Interchange) standard code used to
represent codes
each character (or symbol) as sequence of n=8,so that
each character has 8 bits to restore .This enables each
character to store the same amount of storage space.
On the other hand ,a Variable-length code represented
characters( or symbols) in different number of bits.
Lemma 9.2: T is an optimal tree for the n weights w1
< w2 < ... <wn, then there exist an optimal tree T in
which the terminal vertices weights w1 and w2 are
siblings at the maximal level.
Theorem 9.17: Let T be an optimal tree for the weights
w1+ w2+ w3,...,wn where w1 < w2 < w3 < ,..., <
wn. At the terminal vertex with weight w1 + w2 to
the children of this former terminal vertex. The new
binary tree T1 so constructed is then optimal for the
weights w1,w2,w3,...,wn.
Corollary 9.7: There is an optimal binary tree T where
the weight w1 and w2 are both of the same level.
Example 2: Construct an optimal prefix code for the
symbols a, b, c, d, e, f that occur with frequencies
5, 20, 32, 16, 13, 6.
Solution: First is to rearrange the frequencies in
order from lowest to highest as shown in Figure
9.38a. secondly ,we will combine weights 5 and 6
as reflected in figure 9.38b. thirdly, we merge the
weight 11 with 13 as noted in figure 9.38c.
Fourthly, we combine 16 and 20 as seen in figure
9.38d. Then , we connect 32 with 24 to obtained
56 as shown in figure 9.38e.lastly,we combine the
two sub-trees to produce a single tree as noted in
figure 9.36f.
Here is how the Huffman tree was generated:
initial vertices {(a 5),(b 20),(c 32),(d 16),
13),(f 6)} (e
Merge {({a f} 11),(b 20),(c 32),(d 16),(e

13)} {({a e f} 24),({b d} 36),(c 32)}


Merge {({a c e f} 56),({b d} 36)}
{({a c b d e f) 92)
Mergeobtaining the rooted tree we than write Os
After
and 1s in the branches of the trees to indicate
the codes in each of the characters of a, b, c,
Merge
d, e, and f.
Let say example we have a message of
abedaefac it will be represented as
0001100110000001000100001 which contains
25 bits.
Now if we will compute with weight of the
rooted tree we can get:

The weight of the rooted tree is 204.


Enrichment Exercise:
Construct an optimal prefix code for the
symbols a,b,c,d,e,f,g that occur with
frequencies 2,5,16,8,20,3,12 and
determine the weight of the rooted tree.
Exercises :
Section Exercise 9.1
A. Given the vertices below, construct a tree with
the ff. conditions:
Section Exercise 9.1
B. Given the vertices below, draw a forest with the ff.
conditions:
1. 3 components 3. 2 component with vertex of degree 3.

2. 4 components 4.3.components with 1 vertex of degree 4.


Section Exercise 9.2
Section Exercise 9.2
Given the tree above, answer the following
question?
1.What vertices are leaves?
2.What vertex is the root?
3.What vertex is the parent of vertex g?
4.What vertices are the descendants of vertex
d?
5.What are the ancestors of vertex e?
6.What vertices are the siblings of vertex k?
7.What is the vertex oflevel of vertex m?
Exercises :
8. What vertices are at level 2?
9. What is the height of the tree?
10.Contruct three different subtrees of the given tree
above?
Exercises:
A. Determine whether the trees are full m-ary
,complete m-ary or not an m-ary tree.
b. Determine whether the trees are balance or not
balanced
Section Exercise 9.3
1.Determine the terminal vertices, internal vertices and
all the vertices of a full ternary tree height 8.

2.How many vertices do a full 5-ary tree with 100


internal vertices?

3.Suppose 300 people enter a nationwide double’s


badminton tournament. Determine how many games
must play to determine a champion tem, if a team is
eliminated after 1 loss.

4.How many leaves does a full 6-ary tree with 73


vertices have ?
Section Exercise 9.3
D. In the following binary tree representation left
child-right child of each node are given. Draw the

binary
vertex tree.
r a(r is bthe croot)d e f g h
L child a b - e - - - - -
1.
R child - c d f - g ‘- h -

2. Vertex r a b c d e f g
L Child a c - - - - - -
R Child b d e - - f g -
E. Write the left-child-right child representation of the
binary tree below.
Vertex r a b c d e f g h
1. L child
R child

2.

Vertex r a b c d e f g h
L child
R child
Exercises :
Section Exercise 9.4A&B
A. Determine the breadth-first traversal and the
three depth-first search traversal (in-order ,
pre-
order and post-order)
Breadth-first=

Inorder=

Preorder=

Postorder=
Exercises :
Section Exercise 9.4A&B
Breadth-first=

Inorder=

Preorder=

Postorder=

Breadth-first=

Inorder=

Preorder=
Exercises :
Section Exercise 9.4A&B

Breadth-first=

Inorder=

Preorder=

Postorder=
Section Exercise 9.4 C
A. Given the expression below, determine the infinix,prefix and
postfix notations and draw its binary tree representations.

a.Expression=(a+b)/(c*(d-(e^f)))
Infinix=

Prefix=

Postfix=

b.Expression =((A+)*c-(d-e)
Infinix=
Prefix=
d. Expression =((a^b)+(c+d))+((e*f) /(g+h))
Infinix=
Prefix=

Postfix=
c. Expression =((a-b)+c)*((d+e)*(f/g))
Infinix=
Prefix=
Postfix
=
Exercises :
Section Exercise 9.4C
C. Calculate the following expressions.
1. 36 2 5 3 16 4 / * - - / 18 + 4. / * 10 + 3 5 ^ + 3
12
Exercises :
Section Exercise 9.4C

2. 32 4 + 2 * 9 / 15 6 - + 5. * + / 15 5 7 – 8 2
Exercises :
Section Exercise 9.4C

3. 24 4 / 3 2 ^ + 6 4 * - 6. / + 8 / * 10 3 + 6 – 9 ^ 2 3
Exercises :
Section Exercise 9.5
A. Determine the minimum spanning tree of the following
weighted graphs using prim’s algorithm and provide the solution
on the sequence of partitions.
P0=

P1=

P2=
P3
=

P4=
Exercises :
Section Exercise 9.5a

P0=

P1=

P2=
P3=

P4=
Exercises :
Section Exercise 9.5a

P0=

P1=
P2=

P3=
P4=

P5=
Exercises :
Section Exercise 9.5b
B. Determine the minimum spanning tree of the following
weighted graphs using kruskal’s algorithm and provide the
solution on the sequence of partitions.
P 0=

P1=

P2=
P3=
P4=

P5=
P6=
Exercises :
Section Exercise 9.5b

P0=

P1=
P2=

P3=
P4=

P5=
Exercises :
Section Exercise 9.5b

P0=

P1=

P2=

P3=
P4=

P5=
Exercises :
Section Exercise 9.6
Construct the optimal prefix code for the symbols
with their corresponding frequencies and determine
the weight of the rooted trees.
Symbols a b c d e f g h
Frequency 2 4 6 8 13 15 19 27

Send the message afghdefgb using the binary code


obtained.
Exercises :
Section Exercise 9.6
Symbols a b c d e f g h i

Frequency 1 1 2 4 6 9 14 24 35

Send the message ifdcehfbh using the binary code obtained.


Chapter 9: Review Exercise

 A. Answer the following:


 1. Draw a tree with 9 vertices such that three vertices are of degree
3.
 2. How many edges are there in a tree with 14 vertices.
 3. How many vertices are there in a tree with 17 edges?
 4. Find all trees with 4 vertices
 5. Construct a graph G with 5 vertices such that % has exactly 5 edges
but G is not a tree?
 6. Construct the tree of the first four level of fibonacci sequence.
 7. Find the number of isomers of the (a). Hexanes, C6H14 and (b)
Heptanes, C7H16.
Chapter 9: Review Exercise

 B. Answer the following using the rooted tree


of figure 9.25.
 1.What are the terminal vertices?
 2. What is the root of the tree?
 3. What vertex is the parent vertex c?
 4. What are the descendants of vertex h?
 5. What are the ancestors of vertex h?
Chapter 9 Review Exercise
 6. What are the levels of vertices p
and k?
 7. What vertex is the sibling of vertex
m?
 8. What vertices are at level 4?
 9. What is the height of the tree?
Chapter 9 Review Exercise
 C. Solve the following:
 1.How many internal vertices does a full 5-ary tree with height
3?
 2.Suppose you want to organize a chess single elimination
tournament. If there are 500 costesians, what is the minimum
number of rounds that will be needed ?
 3.An IT company is set up where 92 employees are hired. The
recruitment is initialized by the owner, who hires four
managers. Each manager then hires four other supervisor,
some of whom in turn to hire four others, and so on. (Any newly
hire office administrator hires other four.) How many hiring are
made in reaching all 82 employees?
Chapter 9 Review Exercise
 4. A computer laboratory class which is connected to a wal
socket that has three outlets. Connections are made using
extensions cord that can have three outlets. Connections
are using extensions cords that can have three outlets
each. What is the least number cords that needed to set
up the 40 desktop computers for class use?
 5. At a UAAP-NCAA single elimination tournament with 18
teams from different colleges an universities. How many
matches did the tournament champion played? How many
matches are played in the tournament?
Chapter 9 Review Exercise
 D. Write the left child-right child array representation
of the following binary trees.
 1. Figure 9.39 3. Figure 9.41 5. Figure 9.43
4. Figure 9.42 6. Figure 9.44
 2. Figure 9.40
 E. Determine whether the rooted trees are balanced
or not in the following figures.
 1. Figure 9.39 3. Figure 9.41 5. Figure 9.43
4. Figure 9.42 6. Figure 9.44
 2. Figure 9.40
Chapter 9 Review Exercise
F. Rooted trees.
1. Figure 9. 39
2. Figure 9. 40
Figure 9.39
Figure 9.40
Chapter 9 Review Exercise
F. Rooted trees.
3. Figure 9. 41
4. Figure 9. 42

Figure 9.41 Figure 9.42


Chapter 9 Review Exercise
F. Rooted trees.
5. Figure 9. 43
6. Figure 9. 44
Figure 9.43 Figure 9.44
G. Find the infix , prefix, and postfix notations of the
following expressions and draw its binary tree
represetations.
1.((a+b)*c/(d+e) 3. (((a+b)-c)*d)/e
2.a+((b*c)-d) 4. (((a*b)-
(c+d))^(e/f))-g

H. Calculate the following notations.


1. 4 2 ^ 3 2 ^ + 3 / 2 + 4. - ^ * 7 2 2 20
2. 4 5 6 8 2 - * ++ 5. + - ^ 3 3/ 4 2 * 9 7
3. 8 2 3 * - 4 ^ 16 8 / + 6. + - * 6 4 20 / ^ 3 2
3
I. Establish the following:

1.Construct an optimal prefix code for the


symbols a, b, c, d, e, f that occur with
frequencies 1, 8, 40, 17, 13, 6.
2.Construct an optimal prefix code for the
symbols a, b, c, d, e, f, g that occur with
frequencies 5, 60, 12, 20, 34, 6, 120.
3.Construct an optimal prefix code for the
symbols a, b, c, d, e, f, g, h that occur
with frequencies 1, 2, 3, 6, 14, 17, 30, 75.
J. Determine the minimum spanning tree of the
following weighted graphs using Prim’s and
Kruskal’s algorithms and provide the solution on
the sequence of partitions.
1. 3.
J. Determine the minimum spanning tree of the
following weighted graphs using Prim’s and
Kruskal’s algorithms and
p. rovide the solution on the sequence
of partitions.
2. 4.

You might also like