CIS 2101-Exercise On Trees
CIS 2101-Exercise On Trees
Given a tree: Based on the illustration of a tree at the left, answer the following and make
NOTES by determine the meaning of each red boldface term.
1) What is a tree?
2) What is the parent node of node F?
3) Which nodes are ancestors of node E?
4) Which nodes are proper ancestors of node E?
5) Which nodes are descendants of node H?
6) Which nodes are leaves ?
7) What is the right-sibling of D? E? F?
8) What is the root node ?
9) What is the depth of node E?
10) What is the height of node E?
11) What is the height of the tree?
12) Which nodes are to the left of node G?
13) Which nodes are to the right of node B?
14) How many different paths of length two are there?
15) How many different paths of length zero are there?
16) List the nodes of the tree in preorder.
17) List the nodes of the tree in inorder.
18) List the nodes of the tree in postorder
19) Is the tree on the left a binary tree (Yes/No)?
B. Expression Tree
Based on the illustration of the expression trees at the left, answer the
1) Expression tree of following and make NOTES by determine the meaning of each blue boldface
(a + b) * (c – d) term.
Expression
Prefix Infix Postfix
Tree
1
2) Expression tree of 2
a + b * c – d
3) What are Polish and Reverse Polish Notations?
4) Draw the expression tree of the following mathematical expression.
Use ^ (caret) for exponentiation.
2𝑦3 +1
𝑥= 𝑦−4
C. Huffman Tree
A. Based on the illustration of a tree on the left, answer the following and
make NOTES by determine the meaning of each red boldface term.
Symbol Frequency
a 35% 1) Show the step by step solution in creating the Huffman tree.
b 20% 2) Determine how the Huffman Code is obtained.
c 10% 3) Determine the average of code.
d 15%
B. Given the letters and their probability of occurrence, using Huffman
r 15% algorithm, determine the Huffman Tree, Huffman code and the Average
! 5% code length of the following:
100%
Symbol Frequency
A 25%
Huffman Tree B 15%
C 5%
D 15%
E 20%
F 20%
100%
Note: There can be many answers for the Huffman Tree and Huffman code
but the average code length is the same.
Huffman Code
Symbol Huffman Code
a 0
b 111
c 1011
d 100
r 110
! 1010