简体   繁体   English

生成B树/ 2-3-4树时的插入顺序

[英]Sequence of insertions when generating B-Tree / 2-3-4 tree

Does anyone know about how the sequence of insertions matter for 2-3-4 Trees? 有谁知道2-3-4树插入顺序的重要性吗? Or B-Trees? 还是B树?

It seems the formula for minimum height is log m (k+1) where m is the max no. 看来最小高度的公式是log m (k + 1),其中m是最大数。 of children and k is the number of keys 的数量,k是键的数量

And the formula for max height is: log n ((k+1)/2) where n is the min no. 最大高度的公式为:log n ((k + 1)/ 2)其中n是最小编号。 of children an internal node can have. 内部节点可以拥有的子级数。

But what sequence of insertions actually get these results?! 但是什么顺序的插入实际上可以得到这些结果? I don't know. 我不知道。

It has been suggested to minimise the height of the 2-3-4 tree, you would take the median of the linear sequence eg. 建议最小化2-3-4树的高度,例如,取线性序列的中位数。 1,2,3,4,5,6,7,8 it being 4, and insert that, before rinse repeating for the sub lists either side of the median. 1,2,3,4,5,6,7,8为4,然后插入,在对子列表重复冲洗之前,请在中间值的任一侧进行重复。 Is this true? 这是真的? And if so, what sequence maximises the height? 如果是这样,什么顺序可以使高度最大化?

Yes, the sequence of insertions matters. 是的,插入顺序很重要。 Obviously, the tree will be taller for the same number of keys if more nodes are 1-nodes. 显然,如果更多节点为1节点,则对于相同数量的键,树将更高。 They way to maximise the number of 1-nodes in the tree is to continually expand one branch of the tree to 4-nodes, increasing the height of the tree while leaving many nodes as 1-nodes. 他们最大程度地增加树中1个节点的数量的方法是将树的一个分支连续扩展到4个节点,在增加许多树节点1个节点的同时,增加树的高度。 Essentially, insert the keys pre-sorted. 本质上,插入预先排序的密钥。 1,2,3,..,k. 1,2,3,...,K。 For a minimum height tree, you want to expand in all branches evenly so as to fill up each layer of the tree. 对于最小高度的树,您想在所有分支中均匀展开,以填满树的每一层。 So, you insert the median of the keys, split up the insertion list at this key and then insert the medians from the two halves of the list and so on.. 因此,您插入键的中位数,在该键处拆分插入列表,然后从列表的两半中插入位数,依此类推。

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

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