简体   繁体   English

CLRS 18-2.4假设我们将键{1,2,…,n}插入最小度为2的空B树中。最终B树有多少个节点?

[英]CLRS 18-2.4 Suppose that we insert the keys {1,2,…,n} into an empty B-tree with minimum degree 2. How many nodes does the final B-tree have?

假设我们将键{1,2,…,n}插入最小度为2的空B树中。最终B树有几个节点?

We know that every node except the root must have at least t−1=1 keys, and at most 2t−1=3 keys. 我们知道,除根节点外的每个节点都必须至少具有t-1 = 1个密钥,最多2 t-1 = 3个密钥。 The final tree can have at most n−1 nodes when n≥2. 当n≥2时,最终的树最多可以具有n-1个节点。 Unless n=1 there cannot ever be n nodes since we only ever insert a key into a non-empty node, so there will always be at least one node with 2 keys. 除非n = 1,否则将永远不会有n个节点,因为我们只会将一个密钥插入一个非空节点中,因此将始终至少有一个带有2个密钥的节点。 Next observe that we will never have more than one key in a node which is not a right spine of our B-tree. 接下来观察到,在一个不是B树的正确主干的节点中,我们永远不会有一个以上的键。 This is because every key we insert is larger than all keys stored in the tree, so it will be inserted into the right spine of the tree. 这是因为我们插入的每个键都大于存储在树中的所有键,因此它将插入到树的右脊中。 The fewest possible number of nodes occurs when every node except the deepest node in the right spine has 2 keys and the deepest node in the right spline has 3 keys. 当除右主干中最深的节点之外的每个节点都具有2个键,而右样条中的最深节点具有3个键时,则可能出现的节点数最少。 So at height 1, 1 nodes, at height 2, 3 nodes, …, at level h, 2^h−1 nodes. 因此,在高度1,1个节点,在高度2,3个节点,…,在水平h,2 ^ h-1节点。 In this case, n =2^(h+1)−1 where h is the height of the B-tree, and the number of nodes in B-Tree is #nodes = 2^(h+1)−2−h = n−lg(n+1). 在这种情况下,n = 2 ^(h + 1)-1,其中h是B树的高度,B树中的节点数为#nodes = 2 ^(h + 1)-2-h = n-lg(n + 1)。 So for any n, the final B-Tree must have n−⌊lg(n+1)⌋≤#nodes≤n−1 (if n≥2). 因此,对于任何n,最终的B树必须具有n−lg(n + 1)≤≤nodes≤n-1(如果n≥2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM