简体   繁体   English

具有给定键的节点数最少的 2,4 树

[英]2,4 tree with the fewest number of nodes with the given keys

suppose we have a set of keys K = {1, 2, 3, 4, 5, 6,..., 15} and we need to build a two four tree out of this such that:假设我们有一组键 K = {1, 2, 3, 4, 5, 6,..., 15} 我们需要从中构建一个二四树,这样:

  • CASE1 : the tree has the minimum number of nodes. CASE1 :树的节点数最少。
  • CASE2 : the tree has the maximum number of nodes. CASE2 :树的节点数最多。

my idea -我的想法-

a node in the two four tree can have upto 3 keys and 4 children per node, if we need to minimise the number of nodes we need to keep the nodes full as much as possible, but do not seem to be able to find a strategy that will guarantee this.二四树中的一个节点最多可以有3个键,每个节点有4个子节点,如果我们需要最小化节点数我们需要尽可能的保持节点满,但是好像找不到策略这将保证这一点。

one way that seemed lucrative was to split the array into three parts and then insert the medians at the root, next the first and the last child are pre-determined and repeat the same process for the rest of the remaining keys.this method also seems to fall short.一种似乎有利可图的方法是将数组分成三部分,然后在根部插入中位数,接下来第一个和最后一个孩子是预先确定的,并对剩余键的 rest 重复相同的过程。这种方法似乎也达不到要求。

we do know that the worst case height for such a structure needs to be near 4 and the best case height to be near 2 (using the 2, 4 tree height properties h ~ log(n))我们确实知道这种结构的最坏情况高度需要接近 4,最佳情况高度需要接近 2(使用 2、4 树高度属性 h ~ log(n))

is there any strategy to approach such problem (any hint would be appreciated)?是否有解决此类问题的策略(任何提示将不胜感激)?

To make a 2-4 tree with the smallest number of nodes:要制作节点数最少的 2-4 树:

  1. Starting with N keys, floor(N/4) of then need to be parents.从 N 个键开始,floor(N/4) of then 需要是父母。 Choose these keys, as evenly distributed as possible to ensure that there are 2-3 keys on either side of them.选择这些键,尽可能均匀分布,以确保它们的两侧各有 2-3 个键。
  2. Repeat the procedure with the parents, until you have at most 3 keys.与父母重复此过程,直到您最多拥有 3 个钥匙。 Those go in the root.根中的那些 go。

So starting with 15 keys, you have 12 leaf-level keys in 4 nodes (3 parents).因此,从 15 个键开始,您在 4 个节点(3 个父节点)中有 12 个叶级键。 Those 3 parents can go in the root.这 3 个父母可以 go 在 root 中。

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

相关问题 如何在给定一组预定密钥的情况下对密钥重新排序,以便在插入B树时使用最少数量的节点? - How to, given a predetermined set of keys, reorder the keys such that the minimum number of nodes are used when inserting into a B-Tree? 计算给定范围内的AVL树中的节点数 - Count the number of nodes in an AVL tree in a given range 如何计算给定算法中树中的节点数? - how to calculate number of nodes in a tree given algorithm? 获取满足所有键的最少值 - Get fewest number of values that satisfies all keys 计算AVL树中给定范围内的节点数 - Count number of nodes within given range in AVL tree 如何计算给定深度的不平衡二叉树中的节点数 - How to calculate the number of nodes in an unbalanced binary tree at a given depth 平衡树中的节点数 - Number of Nodes in a Balanced Tree 给定n个节点上的红黑树,任何根到叶子路径上的红色节点的最大数量是多少? - Given a red-black tree on n nodes, what is the maximum number of red nodes on any root to leaf path? 启发式转弯次数最少 - Fewest number of turns heuristic 给定是二叉树和LCA,找到具有此LCA的节点对的数量? - Given is a binary tree and a LCA , find the number of pair of nodes which have this LCA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM