非二叉树可以按顺序遍历吗?

发布于 2024-09-12 22:20:31 字数 270 浏览 1 评论 0原文

我们在这里处理最相似的邻居算法。该算法的一部分涉及按顺序搜索树。

问题是,到目前为止,我们还无法使该树成为二叉树。

是否有类似于非二叉树的顺序遍历。特别是,我认为有,只需从左到右遍历节点(并且仅处理父节点一次?”)

更新

这棵树将在每个节点中都有一个包含 n 个对象的小图。每个节点将有 n 个子节点(每个节点 1 个)图中的每个元素),每个都将是另一个图。所以它的“某种”ab 树,没有所有溢出 - 下溢机制所以我猜最相似的顺序遍历将类似于 btree 中序遍历?

We are dealing with a Most similar neighbour algorithm here. Part of the algorithm involves searching in order over a tree.

The thing is that until now, we can't make that tree to be binary.

Is there an analog to in order traversal for non-binary trees. Particularly, I think there is, just traversing the nodes from left to right (and processing the parent node only once?")

Update

This tree will have in each node a small graph of n objects. Each node will have n children (1 per each element in the graph), each of which will be another graph. So its "kind of" a b tree, without all the overflow - underflow mechanics. So I guess the most similar in order traversal would be similar to a btree inorder traversal ?

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

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

发布评论

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

评论(2

小苏打饼 2024-09-19 22:20:31

是的,但您需要定义顺序是什么。后序和前序是相同的,但中序定义了分支与节点的比较方式。

Yes, but you need to define what the order is. Post and Pre order are identical, but inorder takes a definition of how the branches compare with the nodes.

早乙女 2024-09-19 22:20:31

除了二叉树之外,没有其他树的有序序列的简单模拟(实际上有序是从二叉搜索树中获取排序元素的一种方法)。

您可以在高德纳 (Knuth) 的《计算机编程艺术》第一卷中找到更多详细信息。 1,第 336 页。

如果广度优先搜索可以满足您的目的,那么您可以使用它。

There is no simple analog of the in-order sequence for trees other than binary trees (actually in-order is a way to get sorted elements from a binary search tree).

You can find more detail in "The art of computer programming" by Knuth, vol. 1, page 336.

If breadth-first search can serve your purpose then you can use that.

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