You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

为弥补红黑树高度不可控问题提出多叉搜索树即为B-树 B树满足一下条件

  1. 树中每个节点至多有M个孩子节点即至多有m-1个关键字
  2. 除根节点外其他节点至少有m/2个孩子节点
  3. 若根节点不是叶子节点则根节点至少有2个孩子节点
  4. 所有叶子节点都在同一层上即B树是所有结点的平衡因子均等于0的多路查找树。

如下图所示一颗3阶b树 !微信截图_20221216171144.png

每个节点都会存储key、data、指针(如图5阶B树) !1446087-bc023e47bc74cfa1.webp

B-tree的插入

与BST相同比较大小后判断放在左还是右

B-tree的删除

需要先判断节点是否富有富有删除一个key剩余key的数量大于等于(m/2)向上取整-1。 节点如果不富有需要从兄弟、父亲节点借。如果都不富有只能降低树的高度。具体过程参考B站站长数据结构

B-tree模拟 B-Tree Visualization (usfca.edu)