Java Reference
In-Depth Information
Here is a tree with the same number of leaves as branches:
1
2
3
4
5
6
3. (a) 3 levels
(b) 3 branches: Nodes 3, 5, and 2
(c) 3 leaves: Nodes 1, 4, and 6
(d) The node containing 3 is the root.
(e) Node 5 is the sibling of Node 2. Nodes 4 and 6 are the children of Node 2.
4. preorder:
3 5 1 2 4 6
inorder:
1 5 3 4 2 6
postorder:
1 5 4 6 2 3
5. preorder:
19 47 23
2 55 63 94 28
inorder:
23 47 55
2 19 63 94 28
postorder:
23 55
2 47 28 94 63 19
6. preorder:
2 1 7 4 3 5 6 9 8
inorder:
2 3 4 5 7 1 6 8 9
postorder:
3 5 4 7 8 9 6 1 2
7. The method would eventually crash when trying to dereference root to examine
its data or to make a recursive call.
8. public void printPostorder() {
System.out.print("postorder:");
printPostorder(overallRoot);
System.out.println();
}
private void printPostorder(IntTreeNode root) {
if (root != null) {
printPostorder(root.left);
printPostorder(root.right);
System.out.print(" " + root.data);
}
}
9. public void printMirror() {
System.out.print("mirror:");
printMirror(overallRoot);
Search WWH ::




Custom Search