The best algorithm for checking if a BST binary tree is as follows
IsValidBST(root,-infinity,infinity); bool IsValidBST(BinaryNode node, int MIN, int MAX) { if(node == null) return true; if(node.element > MIN && node.element < MAX && IsValidBST(node.left,MIN,node.element) && IsValidBST(node.right,node.element,MAX)) return true; else return false; }
The spatial complexity of this logic, apparently O(logN) , which I assume is the cost of recursion. How was the value reached?
c ++ c algorithm binary-search-tree
Aks 04 Feb '14 at 7:40 2014-02-04 07:40
source share