LowestCommonAncestors
object LowestCommonAncestors
Value members
Concrete methods
Find the lowest common ancestor(s) for a set of nodes in a directed acyclic graph (DAG).
Find the lowest common ancestor(s) for a set of nodes in a directed acyclic graph (DAG).
- Returns:
Set.empty if given nodes have cyclic dependencies Algorithm:
- for each relevant node, find their recursive parents
- create the intersection of all of those sets
- the LCA are those nodes, that do not have any children in that set based on https://www.baeldung.com/cs/lowest-common-ancestor-acyclic-graph