PROBLEM => FIND THE LOWEST COMMON ANCESTOR OF TWO NODES (a & b) IN BINARY SEARCH TREE STEPS => 1.Find whether these two nodes are present in bst.If not found then return NULL. 2.If both nodes are found then there are 4 possibilites => 1.root == a || root == b => return root 2.a is found in left subtree and b is found in right subtree => return NULL from that subtree where we cant find both a & b 3.if a and b are found in left/right subtree return root node * lca...
Below is the code for binary search function with 1 tests in while loop => I have converted the condition which ends the while loop to outside of while as shown in images.
Comments
Post a Comment