1
$\begingroup$

I have been told that inorder tree tranversal of binary search trees returns the tree elements in order. I came up with this binary search tree:

      20
    /
 10
    \
     26

However the inorder tree tranversal of this seems to be 10, 26, 20?! What is wrong here?

$\endgroup$
  • $\begingroup$ "I have been told that inorder tree tranversal", it should have been binary search tree. $\endgroup$ – Turing101 Dec 17 '19 at 13:46
  • $\begingroup$ @HIRAKMONDAL yes I meant to say that $\endgroup$ – RUBEN GONÇALO MOROUÇO Dec 17 '19 at 15:48
  • $\begingroup$ In your "ASCII-art", is the root at the left or at the top? $\endgroup$ – greybeard Dec 17 '19 at 17:07
  • $\begingroup$ (Could you decide on traversal rather than transversal?) $\endgroup$ – greybeard Dec 17 '19 at 17:10
3
$\begingroup$

This is not a valid binary search tree, since 26 is greater than 20 and is in its left subtree.

$\endgroup$
1
$\begingroup$

That is not correct BST as Narek mentioned. BST should be -

 20
/   \
10  26  

For inorder traversal, start visiting tree from Top to bottom and left to right manner and print a node only when it is referenced 2nd time.

So, inorder traversal here would be 10,20,26.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.