我刚刚在 DBMS 中学习了 B-tree 和 B+-tree。我不明白为什么树中的非叶节点具有 [n/2] 和 n 个子节点,当 n 对特定树是固定的时。
这是为什么?和优势?
谢谢 !
我刚刚在 DBMS 中学习了 B-tree 和 B+-tree。我不明白为什么树中的非叶节点具有 [n/2] 和 n 个子节点,当 n 对特定树是固定的时。
这是为什么?和优势?
谢谢 !
这是使 B+ 和 B-tree 平衡的特性,因此,我们可以轻松计算树上操作的复杂度并将其绑定到 O(logn) [其中 n 是数据集中的元素数]。
小修正:每个非叶节点 - 除了根,都有 B/2 到 B 个子节点。仅根允许有少于 B/2 个儿子。
The basic assumption of this structure is to have a fixed block size, this is why each internal block has n
slots for indexing its children.
When there is a need to add a child to a block that is full (has exactly n
children), the block is split into two blocks, which then replace the original block in its parent's index. The number of children in each of the two blocks is obviously n div 2
(assuming n
is even). This is what the lower limit comes from.
If the parent is full, the operation repeats, potentially up to the root itself.
The split operation and allowing for n/2
-filled blocks allows for most of the insertions/deletions to only cause local changes instead of re-balancing huge parts of the tree.