Lowest Common Ancestor
Data structure to find the lowest common ancestor of two nodes in a tree.
__init__
Arguments
G: list[list[int]]: tree as adjacency listroot: int = 0: root of the tree
Complexities
- time:
- space:
lca
Returns the lowest common ancestor of two nodes u and v.
Arguments
u: int: nodev: int: node
Returns
int: lowest common ancestor ofuandv
