

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Unbalanced Trees
incomplete
2: Red-Black Tree
incomplete
3: Rules
incomplete
4: Rotation
incomplete
5: Fix Insert
incomplete
6: Quiz
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In addition to all the rules of a Binary Search Tree, a red-black tree must follow some additional ones:
Each node is either red or black
The root is black. This rule is sometimes omitted. Since the root can always be changed from red to black, but not necessarily vice versa, this rule has little effect on analysis.
All Nil leaf nodes are black.
If a node is red, then both its children are black.
All paths from a single node go through the same number of black nodes to reach any of its descendant NIL nodes.
The re-balancing of a red-black tree does not result in a perfectly balanced tree. It only limits how unbalanced a tree may become. However, its insertion and deletion operations, along with the tree rearrangement and recoloring, are always performed in O(log(n)) time.