中序逆序也算中序吗?

发布于 2024-10-02 03:21:05 字数 193 浏览 0 评论 0原文

我知道中序遍历的工作原理是这样的:

  1. 遍历左子树。
  2. 访根。
  3. 遍历右子树。

但是如果我们有一个算法可以执行以下操作

  1. 遍历右子树呢?
  2. 访根。
  3. 遍历左子树。

这样的树遍历是否也被认为是有序的?

I know inorder traversal works like this:

  1. Traverse the left subtree.
  2. Visit the root.
  3. Traverse the right subtree.

But what if we have an algorithm that does the following

  1. Traverse the right subtree.
  2. Visit the root.
  3. Traverse the left subtree.

Would such a tree traversal be consdered inorder as well?

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

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

发布评论

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

评论(3

淡水深流 2024-10-09 03:21:05

一段时间我也想知道同样的事情。

我想说,它也可以称为中序遍历。结果将是反向排序的数组,而不是左根右排序。

但定义严格要求左根右。

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.

梦途 2024-10-09 03:21:05

它仍然是一个中序遍历。中序是等轴的。

来自维基百科:

遍历非空二叉树
按顺序(对称),执行
递归执行以下操作
每个节点:

  1. 遍历左子树。
  2. 访问根目录。
  3. 遍历右子树。

参考。

It will still be an inorder traversal. Inorder is simetrical.

From wikipedia:

To traverse a non-empty binary tree in
inorder (symmetric), perform the
following operations recursively at
each node:

  1. Traverse the left subtree.
  2. Visit the root.
  3. Traverse the right subtree.

Reference.

夏日浅笑〃 2024-10-09 03:21:05

是的,假设是二叉搜索树,它仍然是中序遍历。该顺序将与首先访问左子树而不是右子树所获得的顺序相反。

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.

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