Class LowestCommonAncestorDynamicGabowSimple
- All Implemented Interfaces:
LowestCommonAncestorDynamic
addLeaf()
operation.
The running time of this algorithm for \(m\) operations over \(n\) vertices is \(O(m + n \log^2 n)\) and it uses
linear space. More specifically, the addLeaf(LowestCommonAncestorDynamic.Vertex) operation is perform in
\(O(\log^2 n)\) amortized time and
findLowestCommonAncestor(LowestCommonAncestorDynamic.Vertex, LowestCommonAncestorDynamic.Vertex) is perform
in constant time.
This implementation is used by the better linear LCA algorithm LowestCommonAncestorDynamicGabowInts and
LowestCommonAncestorDynamicGabowLongs and rarely should be used directly.
Based on the simpler data structure presented in 'Data Structures for Weighted Matching and Nearest Common Ancestors with Linking' by Harold N. Gabow (1990).
- Author:
- Barak Ugav
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.jgalgo.alg.tree.LowestCommonAncestorDynamic
LowestCommonAncestorDynamic.Vertex -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new dynamic LCA data structure that contains zero vertices. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new leaf vertex to the tree.voidclear()Clear the data structure by removing all vertices in the tree.findLowestCommonAncestor(LowestCommonAncestorDynamic.Vertex x, LowestCommonAncestorDynamic.Vertex y) Find the lowest common ancestor of two vertices in the tree.initTree()Initialize the tree the LCA will operate on and create a root vertex.intsize()Get the number of vertices in the tree.
-
Constructor Details
-
LowestCommonAncestorDynamicGabowSimple
public LowestCommonAncestorDynamicGabowSimple()Create a new dynamic LCA data structure that contains zero vertices.Please prefer using
LowestCommonAncestorDynamic.newInstance()to get a default implementation for theLowestCommonAncestorDynamicinterface.
-
-
Method Details
-
initTree
Description copied from interface:LowestCommonAncestorDynamicInitialize the tree the LCA will operate on and create a root vertex.- Specified by:
initTreein interfaceLowestCommonAncestorDynamic- Returns:
- the new root vertex
-
addLeaf
Description copied from interface:LowestCommonAncestorDynamicAdd a new leaf vertex to the tree.- Specified by:
addLeafin interfaceLowestCommonAncestorDynamic- Parameters:
parent- parent of the new vertex- Returns:
- the new vertex
-
findLowestCommonAncestor
public LowestCommonAncestorDynamic.Vertex findLowestCommonAncestor(LowestCommonAncestorDynamic.Vertex x, LowestCommonAncestorDynamic.Vertex y) Description copied from interface:LowestCommonAncestorDynamicFind the lowest common ancestor of two vertices in the tree.- Specified by:
findLowestCommonAncestorin interfaceLowestCommonAncestorDynamic- Parameters:
x- the first vertexy- the second vertex- Returns:
- the lowest common ancestor of the two vertices
-
size
public int size()Description copied from interface:LowestCommonAncestorDynamicGet the number of vertices in the tree.- Specified by:
sizein interfaceLowestCommonAncestorDynamic- Returns:
- number of vertices in the tree
-
clear
public void clear()Description copied from interface:LowestCommonAncestorDynamicClear the data structure by removing all vertices in the tree.- Specified by:
clearin interfaceLowestCommonAncestorDynamic
-