You are viewing a single comment's thread. Return to all comments →
Well , I just did an inorder traversal, stored them in a list and checked if they are in ascending order. If yes, then its a BST , else it isn't.
This would work for all values (signed or unsigned) a node can possess.
When compared with recursion (which has stack depth), space complexity remains the same in worst case.
Time complexity also remains O(n) , only difference being that mine is a 2-pass solution.
Seems like cookies are disabled on this browser, please enable them to open this website
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Well , I just did an inorder traversal, stored them in a list and checked if they are in ascending order. If yes, then its a BST , else it isn't.
This would work for all values (signed or unsigned) a node can possess.
When compared with recursion (which has stack depth), space complexity remains the same in worst case.
Time complexity also remains O(n) , only difference being that mine is a 2-pass solution.