Lowest Common Ancestor of nodes
def lca(root, nodes):
if root is None: return None
if root in nodes: return root
left_lca = lca(root.left, nodes)
right_lca = lca(root.right, nodes)
if left_lca is None: return right_lca
if right_lca is None: return left_lca
return rootBFS (pre-order traversal) of binary tree
row = [root]
while row:
row = [child for n in row for child in (n.left, n.right) if child]