lowest common ancestor Algorithm

In graph theory and computer science, the lowest common ancestor (LCA) of two nodes V and w in a tree or directed acyclic graph (DAG) However, there exist several algorithms for processing trees so that lowest common ancestors may be found more quickly. Their algorithm processes any tree in linear time, use a heavy path decomposition, so that subsequent lowest common ancestor query may be answered in constant time per query. 

Omer Berkman and Uzi Vishkin (1993) observed a completely new manner to answer lowest common ancestor query, again achieve linear preprocessing time with constant query time. This is done by keeping the forest use the dynamic trees data structure with partitioning by size; this then keeps a heavy-light decomposition of each tree, and lets LCA query to be carry out in logarithmic time in the size of the tree.

lowest common ancestor source code, pseudocode and analysis