522
Graphs and Trees
4. Answer the following questions about the accompanying graph with node a as the root.
a. Is it a binary tree?
b. Is it a full binary tree?
c. Is it a complete binary tree?
d. What is the parent of e?
e. What is the right child of e?
f. What is the depth of g?
g. What is the height of the tree?
In Exercises 5–8, draw the expression tree.
5. 3(2 * x − 3 * y) + 4 * z 4 + 1
6. 3(x − 2) * 3 4 + (5 + 4)
7. 1 − (2 − 33 − (4 − 5) 4)
8. 3(6∙2) * 4 4 + 3(1 + x) * (5 + 3) 4
9. Write the left child–right child array representation for the binary tree in the figure.
1
3
2
4
7
5
6
10. Write the left child–right child array representation for the binary tree in the figure.
1
3
2
8 9 10 11 12 13 14 15
4
5
6
7
11. Draw the binary tree corresponding to the left child–right child representation that follows. (1 is the root.)
Left child Right child
2
3
4
0
5
0
6
7
0
0
0
0
0
0
1
2
3
4
5
6
7
a
c
b
e f
g
h
i
d
Graphs and Trees
4. Answer the following questions about the accompanying graph with node a as the root.
a. Is it a binary tree?
b. Is it a full binary tree?
c. Is it a complete binary tree?
d. What is the parent of e?
e. What is the right child of e?
f. What is the depth of g?
g. What is the height of the tree?
In Exercises 5–8, draw the expression tree.
5. 3(2 * x − 3 * y) + 4 * z 4 + 1
6. 3(x − 2) * 3 4 + (5 + 4)
7. 1 − (2 − 33 − (4 − 5) 4)
8. 3(6∙2) * 4 4 + 3(1 + x) * (5 + 3) 4
9. Write the left child–right child array representation for the binary tree in the figure.
1
3
2
4
7
5
6
10. Write the left child–right child array representation for the binary tree in the figure.
1
3
2
8 9 10 11 12 13 14 15
4
5
6
7
11. Draw the binary tree corresponding to the left child–right child representation that follows. (1 is the root.)
Left child Right child
2
3
4
0
5
0
6
7
0
0
0
0
0
0
1
2
3
4
5
6
7
a
c
b
e f
g
h
i
d
