CIT 594 Examples for Assignment 3 (Recursions) Spring 2008, David Matuszek

In case you are having trouble understanding what the assigned methods are supposed to do, I hope these examples will help.

Suppose you have the following binary tree:

and suppose the `BinaryTree` variable named `root` refers to the topmost node of this binary tree. Then:

Method call Returned value
`root.leftmostDescendant()` `[*|"F"|*]`
`root.rightmostDescendant()` `[*|"C"|*]`
`root.numberOfNodes()` `11`
`root.depth()` `5`
`root.containsEqualValue("G")` `true`
`root.containsSameValue("G")` `true` if the string `"G"` in the binary tree is the same (`==`) String "G" that is given as a parameter; `false` if they are in different memory locations, even if they are `equals()` to each other.
`root.leaves()` The Set `{ [*|"K"|*], [*|"I"|*], [*|"J"|*] }`
`root.valuesOf()` The Set ```{ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K" }```
`root.fringe()` The list `[ "K", "I", "J" ]`, with values in that order.
`root.copy()` A duplicate of the binary tree `root`, with all new nodes.
```anotherTree = root.reverse()``` A new `BinaryTree`, with all new nodes, that looks like this:
`root.reverseInPlace()` Same picture as the one immediately above, but no new BinaryTree nodes are created. Instead, the original tree is modified by swapping the contents of the `leftChild` and `rightChild` references.