Applying solution for LCA in DAGs on cyclic graphs?

570 views Asked by At

The answer to My question might be obvious, and I know that obvious answer on paper. I mean when it comes to some examples I understand why we aren't allowed to have loops to run the Lowest Common Ancestor algorithm, but I have problems understanding the papers written for solution of LCA in DAGs. and so which part of solution stops us from using it on cyclic graphs..

what I'm willing to know and would be thankful to be informed about:

  • can you explain one of solutions to LCA problem in DAGs, without too much formuls?
  • can you determine which step has problems with cylcles and why?

in my problem, pairs of nodes to find their LCA are not inside one loop, so I think there might be a way to solve that..

Thanks in advance

1

There are 1 answers

0
kraskevich On

The problem with cycles starts with the definition itself.

The LCA of u and v is defined as a set of such nodes z that z is reachable from u and v and z is not reachable from any other node z' such that z' is reachable from u and v.

It may not exist in a cyclic graph. For instance, if there's a cycle 1->2->3 and two other nodes and edges: 4->3 and 5->3, there is no LCA for 4 and 5 (as all 1, 2 and 3 are reachable from both of them, but they're also reachable from each other).

You could find all nodes that are reachable from u and v (using a dfs or something else) and then check of there is such a node z that is reachable from both of them but not from any other node that satisfies this condition (it would work in polynomial time).

So it's more about having a meaningful a definition of lowest common ancestor than about being able to compute it (as I have shown above, you can compute something like that, but it might not make sense even for two nodes which are not on the same cycle).