Balanced Search Trees
1 2-3 search trees 2-3查找树
1.1 search
- 可找到的key
- 不可找到的key
1.2 insert
- Insert into a 2-node at bottom
- Insert into a 3-node at bottom
- 插入时遵循优先在一个node添加key的原则,如果一个node存在3个key则分割,将中间的key提到上一层,左右两个key分开
- 每次处理4-node的操作步骤是不变的,因此efficient
1.3 summary
- implementation复杂,因此引入红黑树
2 red-black BSTs 红黑二叉查找树
2.1 红黑树定义
- 左倾红黑树
- 查找代码与BSTs相同,但由于better balance,运行更快
package Chapter03;
public class RedBlackBST<Key extends Comparable<Key>, Value> {
private static final boolean RED = true;
private static final boolean BLACK = false;
private Node root;
private