fishy

int depth(v) d = 0 while (!isRoot(v)) v = parent(v) d++ return d
int depth(v) if (isRoot(v)) return 0 else return 1 + depth(parent(v))
int height() allnodes = positions() max = 0 for each v in all nodes h = depth(v) if (h > max) max = h return max
int height(v) if (isExternal(v)) return 0 else h = 0 for each w in children(v) n = height(w) if (n > h) h = n return h + 1
preorder(T,v)
visit(v)
for each w in children(v)
preorder(T,w)
postorder(T,v)
for each w in children(v)
postorder(T,w)
visit(v)
diskspace(T,v)
sz = 0;
if (isExternal(v))
sz = size(v)
for each w in children(v)
sz = sz + diskspace(T,w)
if (isInternal(v))
print(name(v) + ":" + sz)
return sz;
inOrder(v)
if (hasLeft(v))
inOrder(left(v))
visit(v)
if (hasRight(v))
inOrder(right(v))

The in-order traversal is: H D L I M B E A J F K C G
binaryTreePrint()
h = height(root())
bTreePrint(root(),h)
bTreePrint(v,h)
if (hasLeft(v))
bTreePrint(left(v),h)
for (i = 0; i < (h - depth(v)); i++) print(" ")
printline(v)
if (hasRight(v))
bTreePrint(right(v),h)
This prints out the tree, sideways:
H
D
L
I
M
B
E
A
J
F
K
C
G
class BinaryTreeNode {
Object data;
BinaryTreeNode leftChild;
BinaryTreeNode righChild;
}
| Operation | Array | Linked |
| size, isEmpty | O(1) | O(1) |
| elements,positions | O(n) | O(n) |
| replace | O(1) | O(1) |
| root, parent, children, left, right | O(1) | O(1) |
| hasLeft/Right, isInternal, isRoot | O(1) | O(1) |
| insert | O(n) | O(1) |