aryagraph.algorithms.dag.lowest_common_ancestors#

aryagraph.algorithms.dag.lowest_common_ancestors(g: Graph, a: Hashable, b: Hashable) → set[Hashable][source]#

All lowest common ancestors of a and b in a DAG.

A common ancestor (every node counts as its own ancestor) is lowest when none of its descendants is also a common ancestor. Trees have one; general DAGs may have several, or none (empty set). networkx’s lowest_common_ancestor returns just one of these. O(n + m).