If the inorder traversal of a binary tree produces ordered output, is the tree a binary search tree?

143 Views Asked by At

Given a binary search tree, it's easy to see that the inorder traversal returns values from the underlying set in order (according to the comparator that set up the binary search tree).

My question is about the converse of this statement: if we have a binary tree with the inorder traversal producing ordered output, does this imply that the tree is a binary search tree?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes -- the search tree condition will be satisfied at each node, because by definition of inorder every value in its left subtree will be visited before (and thus be smaller) than the value at the node, and similarly for the right subtree.