chapter 8

Chapter 8
Section 8.1
1.
a.
b.
2.
a. 00110000001100011001110010010001111100000000011101001111110000110101000010100010
b. 110001 0001 010 0010 010 111 0110 0011 111 110001 1010 10111 10110 1001
where is waldo
3. Both trees are of height 3. The left tree is neither full nor complete; the right tree is
complete but not full. Neither tree satisfies the conditions for a binary
4.
Office
Cool
Chrome
Programs
Netscape
Microsoft Office
Plugins
Templates
Section 8.2
1.
Left Tree:
In-Order: 32, 30, 40, 55
Pre-Order: 40, 30, 32, 55
Post-Order: 32, 30, 55, 40
Right Tree:
In-Order: 32, 30, 35, 40, 50, 55
Pre-Order: 40, 30, 32, 35, 55, 50
Post-Order: 32, 35, 30, 50, 55, 40
2.
a.
+
/
/
x
*
y
c
3
b
b.
−
x
/
+
y
*
−
z
a
c.
c
b
*
+
/
−
a
x
c
d
y
3. The evaluation of operators is unambiguous in pre- and post-fix notation, but it is
ambiguous with infix. A convention for precedence and association must be defined to
resolve the ambiguity.
Section 8.3
1.
2.
30
15
4
35
20
32
38
18
19
3.
The tree from question 2 is a binary search tree of height 5. It is neither complete nor full.
4.
Left tree:
3
Right tree:
3
1
1
0
0
null
null
null
null
2
2
null
null
5
null
null
5
4
4
null
null
6
null
null
null
null
null
Section 8.4
1.
a.
b.
2.
mother is added as the right child of morn. jane is added as the left child of kept. None of
these insertions change the height of the tree.
3.
Removing node “kept” will have no other effect, as the node has no children. Node
“killed” now has a left child of null. Removal of node “is” will result in the child node
“in” moving up into its spot, and that is all. Node “jack” now has the left child of “in”.
Removal of node “cow” will result in node “cow” being replaced by the largest item in
it’s left sub-tree, namely node “corn”. Node “corn” now has a left child of “build” and a
right child of “dog”. Node “cock” now has a right child of null.
4.
The replacement word (“corn”) is the the inorder predecessor, or the rightmost node in
the right subtree of the left child. The word “crowed” could also be used as a replacement
for “cow”, since it is the inorder successor, or the leftmost node in the left subtree of the
right child.
5.
Because the situation of a node having no children is covered by the first condition. If the
node has no children, we need not find a replacement, i.e. replace this node with null. If
the left child is null, we are to replace the node with its right child. If the node has no
children, the right child is null. We replace the node with null, and that is what we needed
to do.
6.
Because it does not have a right subtree (it is the rightmost node in the subtree).
Section 8.5
1.
2.
0
built
1
is
2
house
3
this
4
that
5
the
6
jack
0
built
1
jack
2
house
3
the
4
that
5
is
6
this
3.
Section 8.6
1.
a 1010, j 1100001011, k 11000011, l 10111, s 0011, t 1101, v 1100000
2.
0
1
*
0
0
+
0
%
1
1
1
−
/
3.
All of the Huffman codes would be 5 bits in length, except for four of the letters, which
would have Huffman codes length 4. The Huffman tree would be a complete binary tree
of height 5. The Huffman code would be only slightly more efficient at representing the
characters than a normal sequential binary code would.