We want to ensure that the height is always O(logn) even after insertion and deletion. Some examples are red-black trees, AVL trees, and splay trees. There are also B trees that has multiple keys per node.
A red-black tree is the same as a binary search tree but it has a few invariants.
- Each node is either red or black.
- The root is black.
- No 2 reds in a row - if you have a red node, its children must be black. This implies if a child is red, its parent must be black.
- Every root-null path has the same number
Every red-black tree with n nodes has a height less than or equal to 2log2(n+1).
No comments:
Post a Comment