Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the practical applications of the lowest common ancestor algorithms? [closed]

I was having a look at this question and then reading about Tarjan's least common ancestors algorithm. I never came across any applications of LCA algorithms before.

Where are such LCA algorithms commonly used?

like image 578
Lazer Avatar asked Aug 22 '10 17:08

Lazer


People also ask

What is the use of lowest common ancestor?

Application of Lowest Common Ancestor(LCA):To determine the distance between pairs of nodes in a tree: the distance from n1 to n2 can be computed as the distance from the root to n1, plus the distance from the root to n2, minus twice the distance from the root to their lowest common ancestor.

What is LCA in tree?

The Lowest Common Ancestor (LCA) of two nodes and in a rooted tree is the lowest (deepest) node that is an ancestor of both and . Remember that an ancestor of a node in a rooted tree is any node that lies on the path from the root to (including ).


2 Answers

In compilers, the LCA of two basic blocks is a place you can put a computation so it is available to both. This might be useful for eliminating common subexpressions, or inserting phi-node for SSA conversion. These algorithms are well evolved and highly optimized, though, so the LCA itself may be hard to see, e.g., SSA and PRE

like image 62
Doug Currie Avatar answered Oct 23 '22 05:10

Doug Currie


Don't know where it is used, but I have a couple ideas where it might get used:

  • computer graphics: often 3D sceneries get split into cubes which form a tree structure. If you have an object which is contained in two such cubes a LCA algorithm gives you the smallest containing larger cube.

  • analysis of gens in order to find the relationships between species and their lowest common ancestor

  • merge algorithms of version control systems

like image 5
Jens Schauder Avatar answered Oct 23 '22 04:10

Jens Schauder