如何验证一个给定的树是二叉搜索树,或不或不、树是二叉

2023-09-11 06:43:10 作者:傻猫猫

我想知道,如果一个给定的二叉树是一个二叉搜索树与否。

I wanted to know if a given binary tree is a binary search tree or not.

我不知道该怎么做呢?

我唯一知道的是,BST意愿序遍历为您提供了升序输出。

The only thing I know is that the inorder traversal of BST will gives you ascending order output.

所以,这是我们需要验证的唯一条件,还是有别的什么,我们想检查一下。

So, is this the only condition we need to verify or is there anything else we are suppose to check.

在情况下,如果有一些其他必要的条件进行检查,它们是什么?为什么这些条件是必要的,以进行检查?因为,我认为,序遍历本身可以告诉你很容易,如果给定的树BST与否。

In case if there are some other necessary conditions to be checked, What are they? and why those conditions are necessary to be checked? Because, I think, INORDER traversal itself can tell you easily if the given tree is BST or not.

推荐答案

是的,如果序树的遍历为您提供了值的严格单调名单足以确定该树是BST。

Yes, if inorder traversal of the tree gives you a strictly monotonic list of values that is sufficient to determine that the tree is a BST.