Algorithm to find lowest common ancestor in directed acyclic graph?

后端 未结 10 909
孤独总比滥情好
孤独总比滥情好 2020-12-02 11:34

Imagine a directed acyclic graph as follows, where:

  • \"A\" is the root (there is always exactly one root)
  • each node knows its parent(s)
  • the no
10条回答
  •  暖寄归人
    2020-12-02 11:56

    I know it's and old question and pretty good discussion, but since I had some similar problem to solve I came across JGraphT's Lowest Common Ancestor algorithms, thought this might be of help:

    • NativeLcaFinder
    • TarjanLowestCommonAncestor

提交回复
热议问题