简体   繁体   English

2-3-4从数字列表生成树

[英]2-3-4 Tree generating from a list of numbers

I have the list of numbers 50,40,60,30,70. 我有数字50、40、60、30、70的列表。 Lets assume I would like to insert these to an empty 2-3-4 Tree. 假设我想将这些插入到空的2-3-4树中。 Which one of these numbers would be the parent root of the tree and why? 这些数字中的哪一个是树的父根,为什么? Is it the insertion order, is it how big the number is? 是插入顺序,是多少个? I would like to be able to draw 234Tree when I'm giving a list of numbers. 当我给出数字列表时,我希望能够绘制234Tree。 I can't seem to do that because I don't know which one to use as a parent root to start with. 我似乎无法做到这一点,因为我不知道要使用哪个作为父根。 Simply, what factor specifies the parent root of this tree. 简而言之,什么因素指定了该树的父根。

In a balanced tree data structure, the root element will usually contain a value close to the median of the items that have been added to it. 在平衡树数据结构中,根元素通常将包含一个值,该值接近已添加到其中的项目的中值。 However, because the tree will usually not be perfectly balanced, you may not have the exact median in the root. 但是,由于树通常不会达到完美的平衡,因此您的根中位数可能不正确。 The exact structure of the tree may be dependent on the order the values were added to it. 树的确切结构可能取决于将值添加到树的顺序。

In your question, you mention adding five items to a 2-3-4 tree. 在您的问题中,您提到将5个项目添加到2-3-4树中。 That will always end up with a two-level tree structure, but the exact structure will vary depending on the order the elements are added. 最终将始终具有两级树结构,但是确切的结构将根据元素添加的顺序而有所不同。 If you add them in the order they're listed in the question, you'll get: 如果按问题中列出的顺序添加它们,则会得到:

root -> <50>
       /    \
  <30,40>  <60,70>

But if you added the elements in another order, you could have 40 or 60 in the root and 50 in one of the leaf nodes. 但是,如果以其他顺序添加元素,则根节点可能有40或60个,叶节点之一可能有50个。

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

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