You are viewing a single comment's thread. Return to all comments →
Python. Should work for any tree not only binary search.
def search(root, v): if root: if root.info == v: return root l = search(root.left, v) if l: return l r = search(root.right, v) if r: return r return None def lca(root, v1, v2): if search(root.left, v1) and search(root.left, v2): return lca(root.left, v1, v2) if search(root.right, v1) and search(root.right, v2): return lca(root.right, v1, v2) return root
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
Python. Should work for any tree not only binary search.