Red-Black Trees
About
Why the Red-Black Coloring ?
Color Example
10(B)
/ \
5(R) 15(R)Why Red-Black Trees ?
What is Black Height ?
Properties
Example
Final Tree Structure
Color Assignment
Red-Black Tree Properties Validation
Property 1: Every node is either red or black
Property 2: The root is black
Property 3: All leaves (null children) are black
Property 4: If a node is red, then both its children are black
Property 5: Every path from a node to its descendant leaves has the same number of black nodes
Red-Black Tree Insertion & Deletion Logic
Insertion Logic
Step 1: Insert as a Red Node
Step 2: Fix Violations (Balancing Phase)
Case 1: Uncle is Red (Recoloring)
Case 2: Uncle is Black or Null (Rotation + Recoloring)
Final Step
Deletion Logic
Step 1: Perform BST Deletion
Step 2: Fix Double Black Problem
Case 1: Sibling is Red
Case 2: Sibling is Black and its children are both black
Case 3: Sibling is Black and has at least one red child
Special Case: Deleting the Root
Balancing via Rotation
Why Rotation Is Needed
Types of Rotations
Left Rotation
Right Rotation
When Rotations Are Used
Double Rotations (Left-Right or Right-Left)
How Rotations Preserve BST Property
Effect of Rotations on Red-Black Properties
Property
Impact During Rotation
Time Complexity
Java Implementation
Structure of Red-Black Tree vs AVL Tree
Last updated