You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Andrey Vernigora edited this page Feb 2, 2019
·
3 revisions
Tarjan Offline Least Common Ancestor
The Tarjan off-line least common ancestor is an algorithm for computing lowest common ancestors for pairs of nodes in a tree (based on the union-find data structure).
The AlgorithmExtensions.OfflineLeastCommonAncestorTarjan returns a delegate that can be queried for each pair. The delegate returns true if there is a common ancestor and assigns the out parameter.
varg=newAdjacencyGraph<int,SEdge<int>>();introot= ...;// root vertexVertexPair<int>pairs= ...;// vertex pairsvarlca=g.OfflineLeastCommonAncestorTarjan(root,pairs);// fetching the ancestorTVertexancestor;foreach(varpairinpairs)if(lca(pair,outancestor))Console.WriteLine("the ancestor of {0} is {1}",ancestor,pair);