Interface LowestCommonAncestorDynamic

All Known Implementing Classes:
LowestCommonAncestorDynamicGabowInts, LowestCommonAncestorDynamicGabowLongs, LowestCommonAncestorDynamicGabowSimple

public interface LowestCommonAncestorDynamic
Dynamic algorithm for Lowest Common Ancestor (LCA) queries.

The lowest common ancestor of two vertices in a tree is the vertex that appear in both vertices paths to the root (common ancestor), and its farthest from the root (lowest). Algorithm implementing this interface support modifying the tree by adding leafs as children to existing parents vertices, while supporting LCA queries.

Use newInstance() to get a default implementation of this interface.

 
 LowestCommonAncestorDynamic lca = LowestCommonAncestorDynamic.newInstance();
 LowestCommonAncestorDynamic.Vertex rt = lca.initTree();
 LowestCommonAncestorDynamic.Vertex n1 = lca.addLeaf(rt);
 LowestCommonAncestorDynamic.Vertex n2 = lca.addLeaf(rt);
 LowestCommonAncestorDynamic.Vertex n3 = lca.addLeaf(n1);

 assert lca.findLowestCommonAncestor(n1, n2) == rt;
 assert lca.findLowestCommonAncestor(n1, n3) == n1;

 LowestCommonAncestorDynamic.Vertex n4 = lca.addLeaf(n1);
 assert lca.findLowestCommonAncestor(n1, n4) == n1;
 
Author:
Barak Ugav
See Also: