M. Bauer
Exam Two
1. Create a binary search tree from the following data which is as balanced as possible.
No leaf node should be more than +/-1 level from any other leaf node. Note: Do not just create a tree from the data encountered in the following order. 78.2, -35.1, 48.2, 12.9,
-14.7, -86.1, 17.4, 92.7, 38.4, -2.8
17.4
-35.1
-86.1
48.2
-14.7
12.9
38.4
-2.8
78.2
92.7
A
B
C
D
G
E
H
I
L
M
J
N
2. Perform a postorder traversal of the tree depicted above.
•
•
•
Traverse its left subtree.
Traverse is right subtree.
Visit the root of the tree.
•
G, L, H, D, B, M, N, I, E, O, J, P, K, F, C, A
3. Evaluate the following prefix notation expression:
* - * 3 5 8 - + 4 6 3
1. 4 + 6 = 10
*
-
*
3
5
8
- 10 3
5
8
7
2. 10 – 3 = 7
*
-
*
3
3. 3 * 5 = 15
* -
15 8 7
4. 15 – 8 = 7
* 7 7
5. 7 * 7 = 49
The result is 49.
F
K
O P
4. Find a minimum spanning tree in the graph.
2
3
5
4
1
2
4
4
3
3
5
6
3
4
2
5
5. Find a Huffman code to store the string, HALEAKALA.
The word “HALEAKALA” is encoded:
• 0101000011100110001
1. List each symbol in the string and the number of times it occurs.
H = 1, A = 4, L = 2, E = 1, K = 1
2. Calculate the total number of symbols in the string uses the probability that dividing the number of times the symbol uses each symbol.
(ie. H = 1, Total# = 9, 1/9 = .11)
0.11 0.11 0.11 0.22 0.44
*H
*E
*K
*L
*A
3. Create a forest consisting of single node trees, each of which has a weight (the probability the symbol is used).
.44
.33
.22
.22
A
.11
L
K
0
L
1
1
H
E
The word “HALEAKALA” is encoded:
• 0101000011100110001
A
0
K
.11
1
0
0
.11
4. Combine the two trees having the least weight in your forest, to create a forest of (n-1) trees. Put the tree with the larger weight in the left subtree of the