Red-black tree insertion fix-up works by inserting the new key as an ordinary binary-search-tree leaf, colouring that new node red, and then repairing only the colour conflict that can arise when its parent is also red. Because a red insertion does not add a black node to any path, black-height equality starts intact; the repair problem is localised to red adjacency.
The fix-up loop reads a small family around the new node: parent, uncle and grandparent. A red uncle usually leads to recolouring and upward propagation. A black uncle leads to one or two rotations plus recolouring. The cases are mirrors across left and right; the mechanism is much smaller than the number of textbook diagrams suggests.
This pillar explains why new nodes are red, how the search path is inherited from ordinary BST insertion, how parent/uncle/grandparent relationships determine cases, how recolouring preserves black height, how inner and outer geometries select rotations, why the root is finally black, why structural rotations remain constant in number, how to implement and test the loop, and which mistakes create trees that look ordered but no longer satisfy red-black guarantees.
Master guide: How Red-Black Trees Work · Pillar: How Red-Black Tree Invariants Work · Foundation: BST Search and Insertion · Generic rotation mechanics
Insertion Starts With the Ordinary BST Path
Comparison Decides the Leaf Position
Follow the comparator exactly as in a normal binary search tree. Move left for smaller keys, right for larger keys and apply the container’s duplicate policy on equality. The red-black layer does not choose a different insertion location.
The New Node Is Structurally a Leaf
It is attached where the search path reaches a black NIL child. Its conceptual children are black NIL leaves, so the new node begins with a clean local boundary for colour reasoning.
Why the New Node Is Coloured Red
Black Would Change One Family of Root-to-NIL Counts
A new black node would add a black contribution only to paths passing through its new position. Equal black height would be disturbed immediately and might require broader repair.
Red Preserves Black Height Initially
A red node adds ordinary depth but zero black contribution. Therefore every pre-existing black-height relationship survives the structural insertion. The only new invariant that can fail is the no-red-red rule with the parent.
If the Parent Is Black, Insertion Is Done
No Red-Red Conflict Exists
The new red node has black NIL children and a black parent, so red adjacency is valid.
Black Height Remains Unchanged
Because the new node is red, the black count on every path is the same as before. No recolouring or rotation is needed. This is the simplest and very common insertion outcome.
If the Parent Is Red, the Grandparent Must Be Black
Why the Grandparent Exists
A red parent cannot be the root in a stable standard red-black tree, because the root is black. Therefore a grandparent is present.
Why the Grandparent Was Black
Before insertion, the tree had no red-red edge. Since the parent was already red, its parent had to be black. The new red child introduces the first local conflict.
The Uncle Is the Parent’s Sibling
Family Language Compresses the Case Analysis
Current node x, parent p, grandparent g and uncle u describe the local configuration needed for insertion repair.
Only the Uncle’s Colour and Geometry Matter Next
If u is red, use recolouring. If u is black—including NIL black—the repair depends on whether x and p form an inner or outer path relative to g.
Case Family One: Red Uncle
Recolour Parent and Uncle Black
Both child branches beneath g gain a black node at the parent/uncle level.
Recolour Grandparent Red
Removing g’s black contribution compensates for those gains, so paths below g keep the same total black count. The local red-red edge disappears, but g may now conflict with its own parent.
Why Red-Uncle Recolouring Preserves Black Height
Left and Right Sides Change Symmetrically
Both p and u switch from red to black. Any path through either child gains one black node.
Grandparent Loses One Black Uniformly Above Them
g changes from black to red, removing one black node from every path through the whole local subtree. Net black count from above g to NIL remains the same. The operation changes where blackness is located, not how much each path contains.
Red-Uncle Repair Can Propagate Upward
Make Grandparent the New Current Node
The potential red-red problem is now between g and g’s parent.
Repeat the Same Logic
If g’s parent is black, stop. If red, inspect g’s uncle and great-grandparent. Recolouring can therefore travel toward the root while the tree shape remains unchanged.
Propagation Reaching the Root
A Recoloured Grandparent Can Become Root
Repeated red-uncle cases can move the current red node to the top.
Colour the Root Black
This may increase the absolute black height of the entire tree by one, but every root-to-NIL path includes the root, so equality remains intact. The stable root-black invariant is restored.
Case Family Two: Black Uncle
Recolouring Alone Cannot Push the Problem Symmetrically
The parent is red while the uncle is black, so simply recolouring both child sides would not preserve black-height relationships in the same way as the red-uncle case.
Local Shape Must Change
One or two rotations redistribute parent, current node and grandparent. Recolouring then assigns black and red roles so no red-red edge remains and black counts match.
Outer Geometry: LL
Current Node Is Left Child of a Left Parent
The red-red path bends outward left-left from grandparent g through parent p to current x.
Right-Rotate Grandparent
Promote p above g. Under the standard repair, p becomes black and g red. The inorder sequence is unchanged, and the formerly red-red vertical pair becomes a black local root with red children or compatible descendants.
Outer Geometry: RR
Mirror Shape
Current x is right child of red parent p, and p is right child of black grandparent g.
Left-Rotate Grandparent
Promote p, recolour p black and g red under the standard formulation. This is the mirror of LL and uses one primitive rotation.
Inner Geometry: LR
Current Is Right Child of a Left Parent
The red-red path bends inward. The median key among p, x and g is x rather than p.
Rotate Parent First
Left-rotate p so x rises into p’s former position. The geometry becomes an outer LL-style relationship relative to g. Then perform the outer-case recolour and right rotation around g.
Inner Geometry: RL
Mirror Zig-Zag
Current x is left child of red parent p, and p is right child of g.
Straighten Then Rotate Grandparent
Right-rotate p to convert the shape into RR-style outer geometry, then apply the left rotation at g with the corresponding recolouring.
Why Double Rotations Are Not New Primitive Operations
Each Step Preserves BST Order
The generic rotation article proves that left and right rotations preserve inorder sequence by moving the middle subtree into the only valid interval position.
Insertion Fix-Up Owns Only the Policy
Red-black insertion decides when the local colour configuration needs an inner normalisation rotation and an outer repair rotation. Reusing policy-neutral rotation helpers avoids duplicating pointer choreography.
Worked Trace: Black Parent Means Zero Fix-Up
Insert 20 Under Black 30
Suppose a valid tree routes new key 20 to a NIL child of black node 30. Attach 20 red.
Check Invariants
20 has black NIL children, parent 30 is black, no black path count changed and the root remains black. The insertion loop can exit immediately. This example is important because not every red insertion creates a repair case.
Worked Trace: Red Uncle Recolouring
Local Shape
Let black 40 have red children 20 and 60. Insert red 10 under red 20.
Repair
Parent 20 and uncle 60 are red. Recolour 20 and 60 black, recolour 40 red and continue at 40. If 40 is root, recolour it black and stop. No rotation was required, yet the colour distribution changed substantially.
Worked Trace: LL With Black Uncle
Local Shape
Let black 30 have red left child 20 and black/NIL uncle on the right. Insert red 10 under 20’s left side.
Repair
Parent is red, uncle black, geometry outer LL. Recolour 20 black and 30 red, right-rotate 30. The local inorder sequence 10,20,30 stays fixed while 20 becomes local root. Black contribution along both sides remains consistent.
Worked Trace: LR With Black Uncle
Local Shape
Let black 30 have red left child 10 and black uncle. Insert red 20 as 10’s right child.
Repair
This is inner LR. First left-rotate 10, moving 20 into the parent position. Now treat the configuration as LL: recolour 20 black, 30 red and right-rotate 30. The final local root is the median key 20.
Insertion Fix-Up Is a State Machine
State Variables Are Small
Current node colour is red, parent may be red, uncle colour is red or black, and geometry is inner or outer.
Transitions Either Terminate or Move Up
Red uncle recolours and sets current=grandparent. Black uncle normalises geometry if needed, rotates/recolours and terminates the local violation. Thinking as a state machine is clearer than memorising six or more diagrams.
Left and Right Cases Are Mirrors
One Conceptual Algorithm Can Be Reflected
If parent is a left child, uncle is on the right; if parent is a right child, uncle is on the left.
Code May Duplicate Mirrors for Clarity
Imperative implementations often write both branches explicitly to avoid direction abstraction overhead or confusion. Tests should ensure the mirror cases remain logically symmetric.
Insertion Needs at Most a Small Constant Number of Rotations
Red-Uncle Cases Use None
They may repeat upward through recolouring only.
Black-Uncle Repair Uses One or Two
Outer geometry uses one grandparent rotation; inner geometry first rotates the parent and then the grandparent. Therefore one insertion performs at most two primitive rotations in the standard algorithm.
Why Recolouring Can Repeat O(log n) Times
Conflict Can Move Up Several Black Levels
A red uncle repair makes the grandparent red and sets it as current.
Tree Height Bounds the Loop
The current node moves upward at least two structural levels in common formulations, and the tree height is O(log n). Thus the whole insertion remains O(log n) even if recolouring propagates to the root.
Parent Pointers Make the Family Easy to Reach
Current→Parent→Grandparent Is Direct
Insertion fix-up repeatedly needs these relatives and the uncle.
Rotations Must Repair Parent Links Perfectly
A stale parent after an earlier rotation can make the next loop iteration inspect the wrong uncle or grandparent. In test builds, validate child.parent reciprocity after every structural change.
A Sentinel NIL Makes Uncle Colour Tests Uniform
Missing Uncle Is Black
If the grandparent lacks the sibling child, conceptual NIL supplies a black uncle.
No Null-Special Case Is Needed for Colour
A colour helper can return black for the sentinel or null. The geometry still distinguishes whether the parent is a left or right child.
Recursive Insertion Versus Iterative Fix-Up
BST Placement Can Be Recursive
A recursive search can return the inserted node or new subtree path.
Fix-Up Is Often Iterative
Once the node exists, walking parent/uncle/grandparent relationships upward is naturally expressed as a loop. Functional red-black trees may instead encode balancing as recursive pattern rewrites during path reconstruction.
Persistent Red-Black Insertion
Immutable Versions Cannot Recolour in Place
Path nodes and locally affected relatives are rebuilt as new coloured nodes while untouched subtrees are shared.
Pattern-Based Balancing Can Replace Explicit Parent Navigation
Functional formulations recognise red-red patterns in newly reconstructed subtrees and return a balanced coloured structure. The invariants remain identical even though control flow looks different from imperative fix-up.
Insertion in an Augmented Red-Black Tree
BST Path Updates Summaries
Subtree size, sum or other aggregates may change along the insertion path.
Rotations Change Local Descendant Sets
Recompute augmentation for demoted and promoted nodes after structural rewiring. Colour changes alone may not alter aggregate values, but rotation certainly can.
Comparator and Duplicate Semantics
Equal Key May Mean Value Update
If comparator equality identifies an existing map key, replace its value and skip structural insertion; no red-black fix-up is needed unless augmentation depends on the value.
Separate Duplicate Nodes Need a Stable Policy
If equal keys become nodes, rotations must preserve the chosen non-strict order. Count-per-key designs avoid many ambiguities and keep colour structure tied to distinct keys.
Common Failure: Insert the New Node Black
Symptom
Black-height mismatch appears immediately on one family of paths.
Repair
Standard dynamic red-black insertion uses a red new node precisely because it preserves existing black counts. If using a specialised alternative algorithm, its different invariant proof must be explicit.
Common Failure: Treat Red Uncle Like Black Uncle
Symptom
Code rotates even when parent and uncle are both red, producing unnecessary or incorrect black-height changes.
Repair
Uncle colour is the first major branch. Red uncle means recolour and propagate; black uncle means geometry plus rotation.
Common Failure: Recolour but Forget to Move Current Up
Symptom
Local parent-child red conflict disappears, but grandparent remains red beneath a red great-grandparent.
Repair
After red-uncle recolouring, set current to the grandparent and continue the loop. The conflict has moved, not necessarily vanished.
Common Failure: Rotate Inner Case Without Updating Current/Parent Roles
Symptom
After the first LR/RL normalisation rotation, code recolours the old parent rather than the newly promoted median node.
Repair
Either update current/parent variables exactly as the textbook state machine specifies or structure helpers so the first rotation returns the new local root and the second step uses explicit node references.
Common Failure: Forget Final Root Black
Symptom
A chain of recolouring reaches the root and leaves it red.
Repair
Normalise root colour before returning the stable tree. Add root-black assertion to every insertion test.
Testing Insertion Cases Systematically
Force Each Case at Root and Internal Positions
Create red-uncle, LL, RR, LR and RL examples when the grandparent is root and when it has a parent.
Use Non-Empty Middle Subtrees
Three-key examples can hide pointer-loss bugs. Give rotations real B subtrees and validate inorder sequence, parent links, node count and augmentation after every operation.
Property-Based Insertion Testing
Compare With a Trusted Ordered Map
Randomly insert and update keys, then compare membership, values and sorted iteration.
Run Full Invariant Validation After Every Mutation
Assert root black, no red-red edge, equal black height, BST ordering, parent reciprocity and augmentation. The first failing operation is far easier to debug than a final corrupted tree.
Two Practical Perspectives on Insertion
Read the Family Colours
The path from new node to root leaves a visible local trace. A red parent tells you there is a conflict; the uncle colour tells you whether to redistribute colour or change shape; geometry tells you which direction to rotate.
Insertion Is Conflict Resolution Under a Constitution
A programmer sees case branches, a mathematician sees black-height preservation, a verifier sees invariant restoration and a systems engineer sees bounded update work. The cases are different procedures for returning one changed neighbourhood to the same global rules.
Frequently Asked Questions
Why Does a Red Uncle Cause Recolouring Instead of Rotation?
Because both child sides of the black grandparent contain red roots. Recolouring both black and the grandparent red redistributes one black contribution symmetrically while removing the immediate red-red conflict.
Why Does a Black Uncle Cause Rotation?
The asymmetry cannot be repaired by the same symmetric recolouring. Rotation changes local shape so recolouring can restore both red adjacency and black-height equality.
More Frequently Asked Questions
Can Recolouring Alone Reach the Root?
Yes. Repeated red-uncle cases can propagate current upward. The final root is recoloured black.
Does Insertion Ever Need More Than Two Rotations?
Not in the standard red-black insertion fix-up. It may recolour through multiple levels, but structural repair at the first black-uncle case uses one or two primitive rotations.
The Pillar Boundary and Sources
What This Article Owns
This pillar owns red-black insertion-specific repair: new-node colour, red parent, uncle cases, upward recolouring, inner/outer geometry and final root normalisation. Invariant definitions and deletion black-deficit cases have separate owners.
Sources and Further Reading
For balanced-search-tree concepts, see Princeton Algorithms: Balanced Search Trees. For the underlying BST insertion path, see eduKateSG: How BST Search and Insertion Work. Generic left/right rewiring is owned by How Tree Rotations Work in Binary Search Trees.
Final Synthesis: Red-Black Insertion Localises the Damage by Inserting Red
The Flow
Insert by BST order, colour the new node red, stop if the parent is black, recolour when the uncle is red, rotate/recolour when the uncle is black, and force the final root black.
Why It Is Efficient
Red insertion preserves black height at the moment of insertion. The remaining conflict involves only nearby colours and geometry. Recolouring can move the issue upward; at most two rotations resolve the structural case. Global logarithmic balance is maintained through small local repairs.
Worked Propagation Trace: Two Recolouring Levels Before the Root
A Conflict Can Move Without Changing Shape
Imagine the new red node x has a red parent p and red uncle u beneath black grandparent g. Recolour p and u black and g red. Now suppose g itself has a red parent higher in the tree and a red uncle at that level. The same recolouring pattern repeats. No rotations have occurred, yet the colour disturbance has travelled upward through two logical families. This trace shows why red-black insertion is not primarily a rotation algorithm. Recolouring is a first-class balancing operation.
The Root Ends the Propagation Cleanly
If the current red node eventually becomes the root, colour it black. All root-to-NIL paths gain the same black contribution, so black-height equality remains valid. The operation can therefore terminate without revisiting lower levels. This is a useful invariant pattern: upward propagation changes where the local conflict lives, but completed lower subtrees remain valid and need not be reopened.
Worked Outer-Case Trace With Real Middle Subtrees
LL Is More Than Three Keys
Let g be black, p its red left child and x the red left child of p. Let A lie left of x, B between x and p, C between p and g, and D right of g. A right rotation at g promotes p. C becomes g’s left subtree, while x and its subtrees remain on p’s left. Recolour p black and g red. The inorder sequence A, x, B, p, C, g, D remains unchanged and every subtree retains its legal key interval.
Why Black Height Still Matches
Before repair, p was red and g black. After repair, p is black and g red. Along paths through x’s side, the black contribution formerly supplied by g is now supplied by p. Along paths through C and D, the same exchange occurs around the rotation. The operation changes ancestry and colour placement together so each descendant path keeps the required black count.
Worked Inner-Case Trace With Real Middle Subtrees
LR First Promotes the Median
Let p be g’s red left child and x be p’s red right child. x has subtrees B and C, with B’s keys between p and x and C’s keys between x and g. Left-rotate p. B becomes p’s right subtree and x becomes g’s left child with p below it. This first rotation has not yet completed red-black repair; it has converted the geometry into an outer case while preserving all key ranges.
The Second Rotation Completes the Colour Repair
Now recolour x black, g red and right-rotate g. C becomes g’s left subtree and x becomes the local root. The final inorder order is unchanged, no red-red edge remains in the local family and black contribution is redistributed consistently. The two-step trace demonstrates why inner cases are best understood as normalisation plus outer repair rather than independent memorised patterns.
Insertion Case Selection as Decision Logic
Decision One: Is the Parent Red?
If not, stop. This first test removes all cases where the red insertion is harmless. It also means the fix-up loop processes only genuine red-red conflicts rather than every ancestor on the search path.
Decision Two: Is the Uncle Red?
If yes, recolour parent and uncle black, grandparent red, set current to grandparent and repeat. If no, identify whether current is on the same outer side as parent or on the inner side. Inner means rotate parent first; outer means rotate grandparent with the appropriate recolouring. This decision tree is the entire standard insertion fix-up compressed into a small state machine.
Insertion With a Shared NIL Sentinel
Every New Real Node Replaces a Black NIL Child
The structural insertion point is a sentinel child. The new red node receives sentinel children of its own. Because the sentinel is black, the new node starts with black children and cannot violate the red-child rule below itself. Only the parent edge needs examination.
Missing Uncle Naturally Means Black Uncle
If the grandparent lacks the parent’s sibling as a real node, that link points to the black sentinel. The insertion case therefore falls into the black-uncle family without special null branching. Uniform boundary representation makes the code more closely match the abstract case analysis.
Insertion, Exception Safety and Comparator Behaviour
Finish Potentially Failing Comparison Work Before Structural Repair
Search for the insertion point may invoke a user-defined comparator that can be expensive or, in some languages, throw an exception. A robust container should avoid partially inserting a node before the ordered path is determined. Once the leaf is attached, the standard colour and rotation repair usually performs only internal structural operations whose failure model is easier to control.
Comparator Equivalence Defines Duplicate Semantics
If the comparator says the new key is equivalent to an existing key, a map may update its value and perform no structural insertion. This matters because unnecessary creation of a red duplicate node would trigger balancing work and change the logical key model. The container’s comparator contract therefore determines whether red-black insertion starts at all.
Insertion Instrumentation: Measure What the Fix-Up Is Doing
Count Recolourings and Rotations Separately
Two insertion workloads can have identical asymptotic complexity and very different repair profiles. Record how often red-uncle recolouring occurs, how many single and double rotations occur and how far conflicts propagate. This can reveal patterned input or implementation regressions without conflating colour writes with pointer rewiring.
Track Search Depth Too
The ultimate purpose of balancing is to keep later ordered operations shallow. Monitoring insertion depth and maximum tree height verifies that invariant maintenance is delivering the intended structural outcome. A fix-up routine can appear active and still be wrong if colour rules are violated in a way that slowly allows height to drift.
Insertion Testing With Case-Directed Generators
Generate Trees Whose Next Insert Has a Known Family Configuration
Instead of hoping random tests hit every case, deliberately construct valid trees where the next key creates red parent/red uncle, LL, RR, LR or RL. Repeat with the grandparent at root and deeper inside the tree. This makes coverage measurable and ensures outer-parent reconnection code is tested.
Then Use Random Sequences for Interaction Bugs
Case-directed tests prove local branches; random sequences prove those branches compose over time. After every mutation, compare logical contents against a trusted ordered map and run a full independent red-black validator. Shrink failing sequences to the shortest reproducer so the colour history becomes understandable.
Insertion Postconditions for Library-Quality Code
Logical Postconditions
The key-value binding must exist according to duplicate semantics, inorder iteration must remain sorted, the node count must change only when a new distinct node was created and lower/upper-bound queries around the inserted key must return coherent neighbours.
Structural Postconditions
The root is black, every red node has black children, recursive black heights match, parent pointers are reciprocal, every node is reachable exactly once and all augmentation metadata recomputes correctly. Search success alone is not enough to certify a balanced-tree insertion.
Why Insertion Is Easier Than Deletion
The Disturbance Is One Red-Red Edge
By inserting red, the algorithm deliberately protects black-height equality. It begins with a narrow failure mode: perhaps one red node now has a red parent. The family around that edge contains enough information to repair the tree.
Deletion Can Remove a Black Contribution Instead
A missing black node affects path accounting, so deletion must reason about siblings and their children and may propagate a deficit upward. Learning insertion first is therefore pedagogically useful: it teaches recolouring, rotations and invariant preservation before introducing black-deficit accounting.
Insertion Engineering: Case Logic Should Be Observable
Log the Family Before Transforming It
For difficult bugs, log current key, parent key and colour, grandparent key and colour, uncle colour, and whether current and parent are left or right children. That compact record identifies the insertion case without dumping the whole tree. After the transformation, log the new local root and colours. Comparing those two snapshots makes it easy to see whether the code entered the wrong mirror branch or recoloured the wrong object after an inner rotation.
Count Propagation Depth Separately From Search Depth
The key may be inserted at depth d, but recolouring may propagate through only part of that path before hitting a black parent. Recording both metrics reveals how much balancing work the workload creates. A tree with healthy logarithmic search depth can still exhibit interesting colour-propagation patterns under structured insertion orders; these metrics help distinguish expected balancing behaviour from a regression.
Insertion and Root Ownership Across Rotations
Internal Grandparent Rotation
If g has a parent above it, the promoted local root must replace g on the correct side of that ancestor. Generic rotation helpers should handle this reconnection and return the promoted node. The insertion fix-up can then continue or terminate without manually rebuilding outer links. Centralising grandparent reconnection prevents one mirror branch from accidentally leaving the rotated subtree detached.
Root Grandparent Rotation
If g was the container root, the promoted node becomes the new root and must ultimately be black. This case tests both structural ownership and colour normalisation. A helper that knows the container or a caller that assigns the returned subtree root must update the root reference before the operation returns.
Insertion Review: Why the Algorithm Is Small Despite Many Diagrams
There Are Only Two Real Questions After Detecting a Red Parent
First: is the uncle red or black? Red means recolour and move upward. Black means shape repair. Second: if shape repair is needed, is the current node on the inner or outer side of its parent? Inner means one normalisation rotation; outer means perform the grandparent repair. Left and right are mirrors. This compression reduces the mental model from a wall of cases to a tiny decision tree.
Every Step Has a Named Invariant Goal
Recolouring removes the immediate red-red edge while preserving black counts. The first inner rotation changes geometry without solving colour by itself. The outer rotation plus recolouring removes the red-red conflict and restores local black-height relationships. Root black normalisation closes the final boundary condition. When each step is tied to a rule, case memorisation becomes unnecessary.
Insertion Review: The Case Table Is a Proof Compressed Into Control Flow
Each branch corresponds to a precise invariant argument. Red uncle recolouring preserves path black counts and moves the conflict upward. Inner black-uncle geometry is rotated into outer geometry without changing inorder order. Outer repair exchanges parent and grandparent roles while recolouring them so red adjacency disappears and black structure remains consistent. The final root-black step normalises the boundary.
Reading the code this way is safer than memorising case numbers. When modifying or optimising an implementation, require every branch to state its precondition, structural transformation and postcondition. If the reason a colour changes cannot be connected to red adjacency or black-height preservation, the branch deserves scrutiny before it is trusted.
Insertion Boundary Cases Worth Testing Explicitly
Insert into an empty tree and verify the new root ends black. Insert beneath a black parent and verify no unnecessary recolouring occurs. Create a red-parent/red-uncle conflict immediately below the root and verify recolouring plus root normalisation. Create each black-uncle inner and outer case with the grandparent both at root and below another parent. These boundary placements exercise the same logical cases while stressing different root and ancestor reconnections.
Also test value replacement for an existing key, because a map update should not create a new red node or trigger balancing. The strongest insertion suite combines these directed examples with long random histories and invariant validation after every mutation.
Next pillar: How Red-Black Tree Deletion Fix-Up Works
One final implementation rule keeps insertion maintainable: a fix-up branch should never depend on a colour or relationship that it has not re-read after a rotation. Rotations change parent, grandparent and uncle identities. Recompute the local family before the next decision instead of carrying stale references forward. This small discipline prevents some of the hardest red-black bugs, where the first transformation is correct but the second action applies the right rule to the wrong node.
Continue the Red-Black Tree Series
How Red-Black Trees Work · How Red-Black Tree Invariants Work · How Tree Rotations Work · How X Works Hub
