中序逆序也算中序吗?
我知道中序遍历的工作原理是这样的:
- 遍历左子树。
- 访根。
- 遍历右子树。
但是如果我们有一个算法可以执行以下操作
- 遍历右子树呢?
- 访根。
- 遍历左子树。
这样的树遍历是否也被认为是有序的?
I know inorder traversal works like this:
- Traverse the left subtree.
- Visit the root.
- Traverse the right subtree.
But what if we have an algorithm that does the following
- Traverse the right subtree.
- Visit the root.
- Traverse the left subtree.
Would such a tree traversal be consdered inorder as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一段时间我也想知道同样的事情。
我想说,它也可以称为中序遍历。结果将是反向排序的数组,而不是左根右排序。
但定义严格要求左根右。
I was wondering the same thing for some time.
I would say, it can be called inorder traversal also. The result would be reverse sorted array instead of the sorting that would come up with left-root-right.
But the definitions are strict on saying left-root-right.
它仍然是一个中序遍历。中序是等轴的。
来自维基百科:
参考。
It will still be an inorder traversal. Inorder is simetrical.
From wikipedia:
Reference.
是的,假设是二叉搜索树,它仍然是中序遍历。该顺序将与首先访问左子树而不是右子树所获得的顺序相反。
Yes, assuming it's a binary search tree, it's still an inorder traversal. The order would be the reverse of that obtained from visiting the left subtree first, instead of the right.