简体   繁体   English

这是已知的森林搜索算法吗? 如果是,它的名字是什么?

[英]Is this a known forest search algorithm? If it is, what is its name?

The problem is: Given this kind of forest:问题是:鉴于这种森林:

在此处输入图像描述 if we have a node, how can we get the descendants of it?如果我们有一个节点,我们如何获得它的后代?

I thought this algorithm that I think is pretty efficient when talking about reading all descendants adding some little overhead in the writing(it's not too much):我认为这个算法在谈论读取所有后代时非常有效,在写作中增加了一些开销(不是太多):

Firstly, to simplify, let's suppose that the number of root nodes is limited to N. We then will need to store a list with the N first primes.首先,为了简化,假设根节点的数量限制为 N。然后我们需要存储一个包含 N 个前素数的列表。 When we create the first node we will assign the 2nd prime of our list (3) to a field name treeId, the second root node gets the 3rd prime, and so on (we can keep a counter of how many roots there are).当我们创建第一个节点时,我们会将列表 (3) 的第二个素数分配给一个字段名称 treeId,第二个根节点获得第三个素数,依此类推(我们可以保留有多少根的计数器)。

To create a child of a parent, we will take the parent's treeId and recursively multiply to the parent of parent treeId and then multiply by 2 (the first prime).要创建父级的子级,我们将获取父级的 treeId 并递归地乘以父级 treeId 的父级,然后乘以 2(第一个素数)。 To know all descendent of a node with nodeId = k, we can do a linear search and get all nodes whose treeId is different than k and is divisible by k.要知道 nodeId = k 的节点的所有后代,我们可以进行线性搜索并获取所有 treeId 与 k 不同且可被 k 整除的节点。

We can remove the limit of N records as root creating another index treeGroupId so that a child will inherit the same treeGroupId of the parent and we verify if two nodes have the same treeGroupId to then apply the first verification algorithm.我们可以删除N条记录的限制,作为根创建另一个索引treeGroupId,这样一个子节点将继承父节点的相同treeGroupId,我们验证两个节点是否具有相同的treeGroupId,然后应用第一个验证算法。

My question is: Is this a known technique to search for Tree decendents?我的问题是:这是搜索树后裔的已知技术吗? Is there any flow in this algorithm.这个算法有没有流程。 If there's can we have better result?如果有我们能有更好的结果吗?

在素因子分解的上下文中,一种已知的解决方案策略是使用所谓的因子树。

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

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