B树的定义
Definition[edit] http://en.wikipedia.org/wiki/B-tree#Technical_description
According to Knuth's definition, a B-tree of order m is a tree which satisfies the following properties:
- Every node has at most m children.
- Every non-leaf node (except root) has at least⌈m⁄2⌉ children.
- The root has at least two children if it is not a leaf node.
- A non-leaf node with k children contains k−1 keys.
- All leaves appear in the same level, and internal vertices carry no information.
B树的高度
1、摘自算法导论第18章 (注意:where the root node is considered to have height 0)
此图摘自http://blog.youkuaiyun.com/v_july_v/article/details/6530142
此方法是的核心思想是关键字的实际总和应该大于或者等于非叶子节点最小总和数与每个非叶子节点最小关键字数之
乘积(另外root节点最少拥有一个关键字)。
2、一棵含有N个关键字的M阶的B-Tree的最大高度是多少?
M阶意味着B-tree每个非叶子节点最多拥有M个孩子,同时最少拥有⌈m⁄2⌉个孩子。为使B-tree达到最大高度,每个节
点的孩子数目应该尽可能的小。因此,root节点只有2个孩子,也就是说第二层只有2个节点。除了root节点之外的非叶子节点都有⌈m⁄2⌉个孩子。
#所在层 → #节点数目
1(root为第一层) →1
2 → 2
3 →2*⌈m⁄2⌉
4 →2*⌈m⁄2⌉^2
5→2*⌈m⁄2⌉^3
......→......
h→2*⌈m⁄2⌉^(h-2)
有N个关键字的B-tree会有N+1个叶子节点。对于h+1层的节点来说,该层节点的个数为N+1>=2*⌈m⁄2⌉^(h-1),可得
h<= log⌈m⁄2⌉(N+1/2) + 1
此方法是的核心思想是叶子节点的实际总和应该大于或者等于叶子节点可以取到的最小值。
有N个关键字的B-tree会有N+1个叶子节点的证明可参考: