Quiz Entry - updated: 2026.11.26
What does the operation removeExternal(w) do in a binary search tree?
It removes the external node w together with its parent v, and puts w's sibling into v's place. The tree stays a proper binary tree, and the ordering property is preserved.
Let v be w's parent and s be w's other child (the sibling, external or internal). After removeExternal(w):
- w and v are gone,
- s is attached where v used to be: as the left or right child of v's parent, or as the new root if v was the root.
Why does the order survive? s was in v's subtree, so it already lies on the correct side of every ancestor of v. Moving it up one level keeps it in the same subtrees of those ancestors.
This one primitive covers all deletions:
- Case 1 (v's children both external): s is external, so v simply becomes a gap.
- Case 2 (one external child w): s is v's internal subtree, which moves up one level.
- Case 3: the key is first moved, then the node it came from is deleted with case 1 or 2.