Class LowestCommonAncestorOfflineUnionFind
- All Implemented Interfaces:
LowestCommonAncestorOffline
Given a tree and a set of pairs of vertices, the algorithm computes the lowest common ancestor of each pair. It traverse the graph by recursively on each sub tree, from the bottom up. For a node u currently processed, it calls the recursive function on each of its child v sequentially, and union u with v, until all the subtree of u is a single set in the union-find data structure. Then, for each query (u,w), if w was already processed, the LCA is the root of the set containing w.
The algorithm uses linear space and runs in O(n+q)α(n+q) time, where n is the number of vertices in the tree, q is the number of queries, and α is the inverse Ackermann function.
Based on 'Applications of Path Compression on Balanced Trees' by Tarjan (1979).
- Author:
- Barak Ugav
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.jgalgo.alg.tree.LowestCommonAncestorOffline
LowestCommonAncestorOffline.IQueries, LowestCommonAncestorOffline.IResult, LowestCommonAncestorOffline.Queries<V,
E>, LowestCommonAncestorOffline.Result<V, E> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new offline LCA algorithm object. -
Method Summary
Methods inherited from class com.jgalgo.alg.tree.LowestCommonAncestorOfflineAbstract
findLowestCommonAncestors
-
Constructor Details
-
LowestCommonAncestorOfflineUnionFind
public LowestCommonAncestorOfflineUnionFind()Create a new offline LCA algorithm object.Please prefer using
LowestCommonAncestorOffline.newInstance()
to get a default implementation for theLowestCommonAncestorOffline
interface.
-