LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

Which three cases does remove(key) distinguish in a binary search tree?

After finding the node v with TreeSearch, the case depends on v's children: (1) both children external, (2) exactly one child external, (3) no child external, i.e. two internal children.

Case v's children Example in 6 → (2, 9), 2 → (1, 5), 9 → (8) How it is removed
1 two external nodes node 5 (a leaf) removeExternal on one of its external children
2 one external, one internal node 9 (left child 8, right external) removeExternal on the external child; the other subtree moves up
3 two internal nodes node 2 (children 1 and 5) replace v's entry by its inorder predecessor's, then remove that node instead

Cases 1 and 2 are easy because v has a gap on at least one side, so the rest of its subtree can simply take v's place. Case 3 has no such gap, and it is reduced to one of the easy cases by moving a neighbouring key into v.

If the search for the key ends at an external node, the key is not in the tree and there is nothing to remove.

Deletion is typically the hardest operation of any data structure, and sometimes the structure even has to be extended just to support it. A practical rule: a new data structure is not finished until removal works.

Go deeper:

From Quiz: ADS / Binary Search Trees | Updated: Dec 01, 2026