B树 B+树 插入删除操作

可视化网址

先分享一个可视化网址:https://www.cs.usfca.edu/~galles/visualization/Algorithms.html

在这里插入图片描述

底部可以调速度和暂停
在这里插入图片描述

首先说一下节点node就是一整块,关键字key就是每一个值
在这里插入图片描述

B树

献上维基百科的定义
According to Knuth’s definition, a B-tree of order m is a tree which satisfies the following properties:

  1. Every node has at most m children.
  2. Every internal node has at least ⌈m/2⌉ children.
  3. Every non-leaf node has at least two children.
  4. All leaves appear on the same level and carry no information.
  5. A non-leaf node with k children contains k−1 keys.

就是M阶的B树会有:(M阶树是每个节点的最大的孩子数量是M)
children:ceil(M/2) ~ M
每个节点中的keys个数:ceil(M/2) – 1 ~ M–1 (如果阶 M = 3,每个节点内keys有 ⌈3/2⌉-1 ~ 3-1 个,即1~2个 keys)
A non-leaf node with M children contains M−1 keys
意思是:一个节点有M个子节点(有M个指针),因为node 左右+中间 分割的,所以这个node的指针会比这个节点的内部key 多一个,如图看这个B+树:
在这里插入图片描述

B+树

定义:https://en.wikipedia.org/wiki/B%2B_tree

  1. Each node except root can have a maximum of M children and at least ceil(M/2) children.
  2. Each node can contain a maximum of M – 1 keys and a minimum of ceil(M/2) – 1 keys.
  3. The root has at least two children and at least one search key.
  4. While insertion overflow of the node occurs when it contains more than M – 1 search key values.

M阶B+树,M is the order of B+ tree:
每个节点的 children 个数:ceil(M/2) ~ M
每个节点内部的 keys 个数:ceil(M/2) – 1 ~ M– 1

B+树的插入

B+树插入:从最底层找到插入key,这个节点中的keys有富余的话则从中间裂开, 然后合到父节点那里,如果这一层也满了也裂开,层层往上。

B+树的删除

关于删除操作,还没很会。。。
B+树删除:借兄弟,借父,再不行就降低高度。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值