4.16 The binary node will be contain a field bool deleted, (initially set to false). When the ++
and – must be changed to bypass any node whose deleted is true. The insert must also be
modified to skip any deleted nodes on insert and should allow reinsertion by just flipping
the deleted bit. For delete, the node is found, and then its deleted bit is set to true.
BinaryNode<Comparable> * findMax(BinaryNode<Comparable> * t)
{
if (t == nullptr) return nullptr;
}
4.17 Let the internal path length of a tree with n nodes, be the sum of all the depths of all the
nodes in the tree and denoted Cn . Then the average depth would be Cn/ N. Consider a
binary search tree with keys {1, 2, … n}. If the tree is rooted at node i, then there are i –1
nodes left of the root and n – i nodes to the right of the root. Hence to compute the average
over all possible roots we have
Cn = n – 1 + [(C0 + Cn–1) + (C1 + Cn-2) + (C2 + Cn-3) + … + (Cn-1 + C0)]/n.
Subtraction reveals that nCn – (n–1)Cn-1 = 2(n – 1) + 2Cn–1, or