Package com.jgalgo.alg.tree
Interface LowestCommonAncestorOffline
- All Known Implementing Classes:
LowestCommonAncestorOfflineAbstract
,LowestCommonAncestorOfflineUnionFind
public interface LowestCommonAncestorOffline
An algorithm for computing the lowest common ancestor (LCA) of two vertices in a tree, offline.
Given a rooted tree, the lowest common ancestor (LCA) of two vertices u
and v
is the lowest vertex
(farthest to root) that has both u
and v
as descendants. The offline version of this problem is given
a tree and a set of pairs of vertices, find the LCA of each pair. There are also the
static and online versions of this
problem.
Use newInstance()
to get a default implementation of this interface.
- Author:
- Barak Ugav
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Queries container forLowestCommonAncestorOffline
computations forIntGraph
.static interface
Result of aLowestCommonAncestorOffline
computation forIntGraph
.static interface
Queries container forLowestCommonAncestorOffline
computations.static interface
Result of aLowestCommonAncestorOffline
computation. -
Method Summary
Modifier and TypeMethodDescription<V,
E> LowestCommonAncestorOffline.Result <V, E> findLowestCommonAncestors
(Graph<V, E> tree, V root, LowestCommonAncestorOffline.Queries<V, E> queries) Find the lowest common ancestors of the given queries.static LowestCommonAncestorOffline
Create a new offline LCA algorithm object.
-
Method Details
-
findLowestCommonAncestors
<V,E> LowestCommonAncestorOffline.Result<V,E> findLowestCommonAncestors(Graph<V, E> tree, V root, LowestCommonAncestorOffline.Queries<V, E> queries) Find the lowest common ancestors of the given queries.If
g
isIntGraph
, the returned object isLowestCommonAncestorOffline.IResult
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
tree
- the treeroot
- the root of the treequeries
- the queries- Returns:
- the lowest common ancestors of the given queries
-
newInstance
Create a new offline LCA algorithm object.This is the recommended way to instantiate a new
LowestCommonAncestorOffline
object.- Returns:
- a default implementation of
LowestCommonAncestorOffline
-