We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi Amith, can you please specify the binary tree you are using. Are you trying with below tree.
----10---911-811
I think my logic should work because if you do an inorder traversal on a binary tree, it should give you elements in sorted order if it is a binary search tree. But in above case, it gives you 8->9->11->10->11 which is clearly not sorted as 11 appears before 10.
I am just comparing the data in previous node with current node (while doing inorder traversal) to ensure the elements are sorted.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Hi Amith, can you please specify the binary tree you are using. Are you trying with below tree.
I think my logic should work because if you do an inorder traversal on a binary tree, it should give you elements in sorted order if it is a binary search tree. But in above case, it gives you 8->9->11->10->11 which is clearly not sorted as 11 appears before 10.
I am just comparing the data in previous node with current node (while doing inorder traversal) to ensure the elements are sorted.