How is a node with exactly one external child removed? Give the example remove(4) where 4's left child is external and its right child is 5.
Call removeExternal(w) on the external child w: it deletes w and v, and v's other child, the internal subtree, moves up into v's place. Here 5 becomes the right child of 2.
Tree before: 6 → (2, 9), 2 → (1, 4), 4 → (external, 5), 9 → (8).
- TreeSearch(4) finds v = 4.
- 4's left child w is external, the right child is 5.
removeExternal(w)deletes w and 4; the sibling, 5 with its whole subtree, takes 4's place.
Result: 6 → (2, 9), 2 → (1, 5), 9 → (8). Inorder: 1, 2, 5, 6, 8, 9.
The ordering property holds automatically. Everything in 4's right subtree was > 2 and < 6 (it sat in 2's right subtree and 6's left subtree), and it is still in exactly those subtrees after moving up. The subtree moves as a whole; nothing inside it is touched.
* The remaining child's subtree moves up one level, unchanged. *