MCPcopy Create free account
hub / github.com/geekcomputers/Python / lca

Function lca

binary_search_tree.py:291–302  ·  view source on GitHub ↗
(t_node, c1, c2)

Source from the content-addressed store, hash-verified

289# It return value in the lowest common ancestor, -1 indicates value returned for None.
290# Note that both values v1 and v2 should be present in the bst.
291def lca(t_node, c1, c2):
292 if c1 == c2:
293 return c1
294 current = t_node
295 while current:
296 if c1 < current.info and c2 < current.info:
297 current = current.left
298 elif c1 > current.info and c2 > current.info:
299 current = current.right
300 else:
301 return current.info
302 return -1
303
304
305# Function to print element vertically which lie just below the root node

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected