Professional Documents
Culture Documents
1. Create a 2-tree to store the algebraic expression “2+3”. Then perform a preorder, inorder,
and postorder traversal of the tree.
2. Create a 2-tree to store the algebraic expression “(2+3)x6”. Then perform a preorder,
inorder, and postorder traversal of the tree.
3. Construct a binary search tree if items are inserted into an empty tree in the order:
G,M,C,J,D,A,K,E
4. Construct a binary search tree if items are inserted into an empty tree in the order:
10,3,5,1,7,11,13,4
A D
K H G
C B E
Figure 1
3
6. [10.6] Consider the algebraic expression E = (2x + y )(5a − b) .
a) Draw the corresponding 2-tree.
b) Use T to write E in Polish prefix form. The constants and the symbols x, y,a,b
will be the external nodes.
€
€ € €
7. [10.7] Draw all possible nonsimilar:
a) binary trees T with three nodes
b) 2-trees T " with four external nodes (use the results to part (a) to do this step)
€ n data items A , A ,…, A are already sorted, i.e., A < A < … < A .
8. [10.9] Suppose 1 2 n 1 2 n
€
a) If the items are inserted in order into an empty binary tree T , describe the final
tree T .
b)€ What is the depth d of the final tree T ?
€ €
€
€
9. [10.10] Suppose the following list of letters is inserted into an empty binary search tree:
€ €
J,R,D,G,W,E,M,H,P,A,F,Q
10. [10.11] Consider€the binary tree T shown in figure 2. Describe the tree after:
a) node M is deleted€
b) node D is deleted
€
€
€ J
D R
A G M W
E H P
F Q
Figure 2
11. [10.13] There are six symbols in a binary tree T and the weight and Huffman code for
each symbol is defined below:
Draw the binary tree T and find the weighted path length P of the tree T .
12. [10.14] Suppose the six weights 4, 15, 25, 5, 8, 16 are given. Find a 2-tree T with the
€ and with a minimum path length €
given weights €
P . Use Huffman’s algorithm to generate
the tree.
€
€
13. [10.15] Suppose data items A,B,C,D, E,F,G occur with the following probability
distribution:
Data item: A B C D E F G
€
Probability: 10 30 5 15 20 15 5
B C
D
E F
G H
Figure 3
15. [10.23] Find the final tree T if the following numbers are inserted into an empty binary
search tree T :
50,33,44,22,77,35,60,40
€
€
16. [10.26] Let T be the binary search tree shown in figure 4. Suppose nodes 20, 55, 88 are
added one after the other to T . Find the final tree T .
€ 5
0
€ €
2 7
5 5
2 4 6 9
2 0 0 0
1 3 4 8
5 0 4 0
3
3
Figure 4
17. [10.27] Let T be the binary search tree shown in figure 4. Suppose nodes 22, 25, 75 are
deleted one after the other from T . Find the final tree T .
€
18. [10.32] Consider the following data items and weights:
€ €
( A,13), (B,2), (C,19), (D,23), ( E,29), (F,5), (G,9)
Find a Huffman coding for the seven letters using a 2-tree with a minimum path length P ,
and find P .
€
€
€
19. Decode the string 101100010110111001100111010001001101111010001011 for the tree
shown below in figure 5. The character 2016 is the ASCII code for space (represented as
sp).
€
0
1
0 1 1
0
a sp
0 1
1 0
s i t
0 1
r w
Figure 5
20. Create a binary tree using Huffman’s coding algorithm to encode the string: