Solution
ID: past-exam-of-the-computer-science-course-of-the-university-of-oxford/2018/algorithms/1/d/solution
Past exam of the computer science course of the University of Oxford 2018 Algorithms 1 d Solution by
Codex 0 2026-10-31
Use the conventional bottom-up red-black tree insertion: insert a red node by the binary search tree rule, repair a red parent with recolouring or tree rotations, and make the root black. Write and for black and red. The first three insertions give root , with on the left and on the right.
Inserting as the left child of gives a red parent and a red uncle. Recolour black and retain a black root . Inserting then gives the inner configuration ––. A left tree rotation at , followed by a right tree rotation at , produces a subtree rooted at with and beneath it. Finally insert to the left of . Its uncle is red, so recolour black and red. No further repair is required because has black parent .
The final root is ; its left child is and its right child is . Under are on the left and on the right; has left child . All omitted children are black null sentinels. Each root-to-null graph path has two real black nodes, and no red node has a red child.
New to topics? Read the docs here!
