0% found this document useful (0 votes)
86 views2 pages

CIS 2101-Exercise On Trees

The document provides instructions and questions for three exercises on tree data structures: 1) A general tree exercise with questions about tree terminology like parent nodes, ancestors, descendants, leaves, siblings, depth, and traversal orders. 2) An expression tree exercise with questions about representing mathematical expressions as trees and calculating prefix, infix, and postfix traversals. 3) A Huffman tree exercise involving constructing a Huffman tree from symbol frequencies and determining the resulting Huffman codes and average code length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views2 pages

CIS 2101-Exercise On Trees

The document provides instructions and questions for three exercises on tree data structures: 1) A general tree exercise with questions about tree terminology like parent nodes, ancestors, descendants, leaves, siblings, depth, and traversal orders. 2) An expression tree exercise with questions about representing mathematical expressions as trees and calculating prefix, infix, and postfix traversals. 3) A Huffman tree exercise involving constructing a Huffman tree from symbol frequencies and determining the resulting Huffman codes and average code length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CIS 2101 Exercise: Trees

April 17, 2020


A. General Tree

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.

1) What is an expression tree ?


2) Determine the prefix, infix, and postfix of expression trees 1 and 2. Fill
in the table below.

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

You might also like