Red-Black Trees
Introduction
Red-Black Trees are a type of self-balancing binary search tree where each node has an additional bit for denoting the color of the node, either red or black. These trees maintain balance during insertions and deletions, ensuring O(log n) time complexity for basic operations.
Properties of Red-Black Trees
Core Rules
- Every node is either red or black
- The root node is always black
- All leaves (NIL nodes) are black
- If a node is red, then both its children are black (no two red nodes can be adjacent)
- Every path from a node to its descendant NIL nodes contains the same number of black nodes
Key Operations
Time Complexity
- Search: O(log n)
- Insert: O(log n)
- Delete: O(log n)
- Minimum/Maximum: O(log n)
Visual Representation
Example of a valid Red-Black Tree structure
Learn More
For more detailed information about Red-Black Trees and their implementation, visit the Wikipedia article on Red-Black Trees.