[英]Is post-order traversal == bottom-up traversal and pre-order traversal == top-down traversal?
Would it be right to say post-order traversal of a tree should be used to do a bottom-up traversal whereas a pre-order traversal should be used to do a top-down traversal of a binary tree?是否应该说应该使用树的后序遍历来进行自下而上的遍历,而应该使用前序遍历来进行二叉树的自上而下的遍历?
This has been true in all the examples that I have encountered, so I just wanted to confirm.在我遇到的所有示例中都是如此,所以我只是想确认一下。 There are some problems for which it is intuitive to start from the leaves (at the bottom).
有些问题从叶子(底部)开始是直观的。 Can we use post-order traversal to solve them (and vice versa)?
我们可以使用后序遍历来解决它们(反之亦然)吗?
Thanks!谢谢!
No. While post-order traversal
and pre-order traversal
have clear definition, bottom-up traversal
or top-down traversal
terms might be interpreted by different ways, they are not generally accepted for binary trees.不可以。虽然
post-order traversal
和pre-order traversal
有明确的定义,但bottom-up traversal
或top-down traversal
术语可能有不同的解释方式,但它们通常不被二叉树所接受。 If anybody uses last terms for trees, exact meaning depends on context.如果有人对树使用最后一个术语,那么确切的含义取决于上下文。
Look at the picture from wiki :看看维基上的图片:
Does pre-order traversal here look like top-down traversal
?这里的预购遍历看起来像
top-down traversal
吗? Or post-order likes bottom-up traversal
?还是后序喜欢
bottom-up traversal
? Seems no.似乎没有。
Perhaps you want to consider BFS methods to get level order也许您想考虑 BFS 方法来获取级别顺序
No. And actually the terms bottom-up / top-down are generally used for graph, but for trees, it's sort of used as explained below:不。实际上,自下而上/自上而下的术语通常用于图形,但对于树,它的使用方式如下所述:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.