Trees & Ordered Maps Medium
2-3 Tree to Red-Black Tree Conversion
Translate each 2-node to one black node and split each 3-node into a black node with a red left child.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(n)
AverageO(n)
WorstO(n)
SpaceO(n)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Follow the source's recursive child order, color assignment, pointer wiring, and subtree-size updates while converting a valid 2–3 search tree.
- A 3-node becomes a black node for its larger key with a red left child for its smaller key.
- For a 3-node, the source converts right, then left, then center children in that order.
- The smaller 3-node key's red node receives left and center subtrees; the black node receives the right subtree.
- Each RBNode starts at size one, then the source adds the sizes of its output children.
- The red node points left from its black parent, matching the source's horizontal red-link representation.
Algorithm code
Javasearching/RedBlackTreeConverter.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1