Professional Documents
Culture Documents
PART A
Answer all the questions
( 5 X 2 = 10 )
3) Write the difference between strictly binary tree and complete binary tree
Complete binary tree is a binary tree in which all the levels must be filled from the left to
right. After filling one level then only we can move on to the next level. Full and Complete
binary trees are different. All full binary trees are complete binary trees but not vice versa.
Strictly Binary Tree: Here each will have exactly two child nodes except the leaf nodes
4) What is the maximum number of nodes in a binary tree of depth k?
The max. no. of nodes in a binary tree of depth k is 2k-1.
Proof:
Max. no. of nodes in a binary tree of depth k =
= 20 + 21 + 22 + + 2k-1
= 2k 1
5) What are the ways to represent Binary tree in memory?
1. Array Representation
2. Linked List Representation
PART B
(2 X 16 +1 X 8 = 40)
6 a) Explain the algorithm for the construction of Huffman code with an example.
(16)
n0 = n2 +1
n2 = n0 1
From eqn 1,
N = n 0 + n0 1
= 2n0 1
Hence N = 2n -1 ( because it is mentioned that no. of leaf nodes is n. Therefore, n0 = n )
Hence proved.
ii) Explain the various representations of binary tree in memory. Represent the following
binary tree using the above representations.
(8)
*
B
E
H
7 a) Explain the algorithm for the conversion of general tree to binary tree for the given tree.
(16)
A
B
C
E
Ans:
Illustrate with stack:
A
B
C
G
D
E
F
(OR)
7 b) Explain in detail about in order, pre order and post order tree traversal with algorithm
and examples. Find in order, pre order & post order for the following tree.
(16)
A
B
Tree Traversal:
Traversing means visiting each node only once. Tree traversal is a method for
visiting all the nodes in the tree exactly once.
Types of traversal:
In order Traversal
Pre order Traversal
Post order Traversal
In order Traversal: - ( L D R ) (Left Data Right )
(i)
(ii)
(iii)
(8)
R
A
G
(OR)
b) Explain the various operations on a binary tree.
1.
2.
3.
4.
5.
6.
7.
(8)
Left (p):If p is a pointer to a node then left(p) gives the left child of the node
Right(p): If p is a pointer to a node then right(p) gives the right child of the node
Father(p):If p is a pointer to a node then father(p) gives the father of the node
Brother(p): If p is a pointer to a node then brother(p) gives the sibling/brother of the node
Isleft(p):It gives the value true if the node is the left child of some node
Isright(p):It gives the value true if the node is the right child of some node
Maketree(x)
It creates a new binary tree consisting of a single node with information x and returns a pointer to that
node
a. Left child
b. Data
c. Right child
It creates a node fill left child , right child to NULL and returns the address.
8.
Setleft(p,x):This function accepts a pointer p with no left child and it creates a new left child for p
with information x.
9. Setright(p,x):This function accepts a pointer p with no right child and it creates a new right child for p
with information x.