n 阶 B 树中可以容纳多少个元素?

发布于 2024-08-28 03:01:22 字数 17 浏览 8 评论 0原文

是2n吗?只是检查。

Is it 2n? Just checking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

万水千山粽是情ミ 2024-09-04 03:01:22

术语
B 树的顺序在文献中的定义并不一致。
(例如,请参阅维基百科有关 B 树的文章的术语部分
一些作者认为它是非叶节点可以容纳的最小键数,而另一些作者则认为它是最大键数非叶节点可以容纳的子节点(比该节点可以容纳的最大键数多1)。
然而,许多其他人通过假设固定长度的键(和固定大小的节点)来回避歧义,这使得最小值和最大值相同,因此顺序的两个定义产生相差 1 的值(正如所说的键的数量是总是比子节点的数量少一。)

我将深度定义为在叶记录的搜索路径中找到的节点数,包括根节点和叶节点。从这个意义上说,一棵非常浅的树,只有一个根节点直接指向叶节点,其深度为 2。如果该树要生长并需要中间级别的非叶节点,则其深度将为 3 等。

如何n 阶 B 树中可以容纳许多元素?
假设固定长度键,并假设“顺序”n 被定义为子节点的最大数量,答案是:

   (Average Number of elements that fit in one Leaf-node) * n ^ (depth - 1)

我如何计算?...:
数据(“元素”)仅保存在叶节点中。因此,持有的元素数量是一个节点中适合的元素的平均数量乘以叶节点的数量。
叶节点的数量本身由适合非叶节点的子节点数量(顺序)驱动。例如,叶节点上方的非叶节点指向 n 个(顺序)叶节点。然后,该非叶节点之上的非叶节点指向n个相似节点等,因此“为(深度-1)次方”。

请注意,上面的公式通常使用平均值(非叶节点中保存的键和叶节点中保存的元素)而不是假设固定键长度和固定记录长度:树的节点大小通常为与键和记录大小相称,因此保存足够大的数字键或记录,使得任何叶子中保存的键或记录的有效数量与平均值相比变化相对较小。

示例
一棵深度 4 的树(一个根节点、两层非叶节点和一层[显然]叶节点)和阶 12(非叶节点最多可以容纳 11 个键,因此指向它们下面的 12 个节点),并且每个叶节点可以包含 5 个元素,将:
  - 让它的根节点指向它下面的12个节点
  - 它下面的每个节点都指向它们下面的 12 个节点(因此“3”层中将有 12 * 12 个节点(假设根是第 1 层等,顺便说一句,这个编号定义也是不明确的......)
  - “第 3 层”中的每个节点将指向 12 个叶节点(因此将有 12 * 12 * 12 个叶节点。
  - 每个叶节点有 5 个元素(在本例中)
因此..这样的树将容纳...

  Nb Of Elements in said tree = 5 * 12 * 12 * 12
                              = 5 * (12 ^ 3)
                              = 5 * (12 ^ depth -1)
                              = 8640

认识第三行的公式。

B 树的显着之处在于,相对较浅的树(根和查找记录之间的“跳跃”次数有限)可以保持相对较高的数字记录。该数字乘以每个级别的订单。

Terminology
The Order of a B-Tree is inconstantly defined in the literature.
(see for example the terminology section of Wikipedia's article on B-Trees)
Some authors consider it to be the minimum number of keys a non-leaf node may hold, while others consider it to be the maximum number of children nodes a non-leaf node may hold (which is one more than the maximum number of keys such a node could hold).
Yet many others skirt around the ambiguity by assuming a fixed length key (and fixed sized nodes), which makes the minimum and maximum the same, hence the two definitions of the order produce values that differ by 1 (as said the number of keys is always one less than the number of children.)

I define depth as the number of nodes found in the search path to a leaf record, and inclusive of the root node and the leaf node. In that sense, a very shallow tree with only a root node pointing directly to leaf nodes has depth 2. If that tree were to grow and require an intermediate level of non-leaf nodes, its depth would be 3 etc.

How many elements can be held in a B-Tree of order n?
Assuming fixed length keys, and assuming that "order" n is defined as the maximum number of child nodes, the answer is:

   (Average Number of elements that fit in one Leaf-node) * n ^ (depth - 1)

How do I figure?...:
The data (the "elements") is only held in leaf nodes. So the number of element held is the average number of elements that fit in one node, times the number of leaf nodes.
The number of leaf nodes is itself driven by the number of children that fit in a non-leaf node (the order). For example the non-leaf node just above a leaf node, points to n (the order) leaf-nodes. Then, the non-leaf node above this non-leaf node points to n similar nodes etc, hence "to the power of (depth -1)".

Note that the formula above generally holds using the averages (of key held in a non-leaf node, and of elements held in a leaf node) rather than assuming fixed key length and fixed record length: trees will typically have a node size that is commensurate with the key and record sizes, hence holding a number key or records that is big enough that the effective number of keys or record held in any leaf will vary relatively little compared with the average.

Example:
A tree of depth 4 (a root node, two level of non-leaf nodes and one level [obviously] of leaf nodes) and of order 12 (non-leaf nodes can hold up to 11 keys, hence point to 12 nodes below them) and such that leaf nodes can contain 5 element each, would:
  - have its root node point to 12 nodes below it  
  - each node below it points to 12 nodes below them (hence there will be 12 * 12 nodes in the layer "3" (assuming the root is layer 1 etc., this numbering btw is also ambiguously defined...)  
  - each node in "layer 3" will point to 12 leaf-nodes (hence there will be 12 * 12 * 12 leaf nodes.
  - each leaf node has 5 elements (in this example case)
Hence.. such a tree will hold...

  Nb Of Elements in said tree = 5 * 12 * 12 * 12
                              = 5 * (12 ^ 3)
                              = 5 * (12 ^ depth -1)
                              = 8640

Recognize the formula on the 3rd line.

What is generally remarkable for B-Tree, and which makes for their popularity is that a relatively shallow tree (one with a limited number of "hops" between the root and the sought record), can hold a relatively high number record. This number is multiplied by the order at each level.

橘味果▽酱 2024-09-04 03:01:22

我的书上说B树的阶是一个节点中可以存储的指针的最大数量。 (第 348 页)“钥匙”的数量比顺序少 1 个。因此 n 阶 B 树可以容纳 n-1 个元素。

这本书是“文件结构”,第二版,作者是 Michael J. Folk。

My book says that the order of a B-tree is the maximum number of pointers that can be stored in a node. (p. 348) The number of "keys" is one less than the order. So a B-tree of order n can hold n-1 elements.

The book is "File Structures", second edition, by Michael J. Folk.

并安 2024-09-04 03:01:22

如果您的元素数量公式在某处不包含幂运算,那么您就做错了。

5 阶二叉树可以容纳 2^0 + 2^1 + 2^2 + 2^3 + 2^4 个元素,因此 31 .. (即 2^order - 1)。

编辑:
我似乎把顺序和深度/长度搞混了。二叉树的顺序到底是什么?您似乎在讨论 B 树,就好像它们根据其定义的本质,每个元素最多包含两个子元素一样。

If your formula for the number of elements doesn't include an exponentiation somewhere, you've done it wrong.

A binary tree of order 5 can hold 2^0 + 2^1 + 2^2 + 2^3 + 2^4 elements, so 31 .. (which is 2^order - 1).

Edit:
I appear to have gotten order and depth / length mixed up. What on earth is the order of a binary tree? You appear to discuss B-trees as if they don't, by the very nature of their definition, hold a maximum of two child elements per element.

决绝 2024-09-04 03:01:22

设b树的阶数为“m”,则表示b树中同一层可以插入的最大节点数=m-1。之后节点将分裂。
例如:如果阶数为3,则在第3个元素到达时只能插入2个最大节点,节点将按照二叉搜索树或自平衡树的属性进行分裂。

Let Order of b-tree is 'm' means maximum number of nodes that can be inserted at same level in a b-tree=m-1.After that nodes will splits.
for ex: if order is 3 then only 2 maximum node can be inserted on arrival of 3rd element ,nodes will splits by following the property of binary search tree or self balancing tree.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文