b/b+树的特点
- 有序
- 平衡(到任意叶子节点的距离相等)
- 高度低,减少磁盘IO,B+用于数据库存储,B树只用于学术研究
b树与b+树的区别
- b树在中间节点和叶子节点上都存储数据
- b+树只在叶子节点上存数据,并且将叶子节点连起来形成链表,方便范围查询
b树定义
- 一个t阶b树,每个节点(除了根节点)至少有t-1个key,最多有2t-1个可以,子节点的个数是key数+1
- 根节点至少有一个key
b树插入
总是从叶子插入,增高是因为叶子分裂
def btree_insert(root, k):
if root is full:
create new empty root
split old root
x = whatever node that contains k
else:
x = root
# 不变量:x is not full
while x is not leaf:
y