Encyclopedia > Tarjan's off-line least common ancestors algorithm

  Article Content

Tarjan's off-line least common ancestors algorithm

In computer science, Tarjan's off-line least common ancestors algorithm is an algorithm based on the least common ancestor[?] property.

The least common ancestor of two nodes d and e in a rooted tree T is the node g that is an ancestor of both d and e and that has the greatest depth in T.

The off-line least common ancestors problem gives us a rooted tree T and a set P = {{d,e}} of unordered pairs of nodes in T.

Tarjan's off-line least common ancestors algorithm determines the least common ancestor of each pair in P.

An example of the algorithm:

 TOLCA(u) {
 Make-set(u);
 ancestor[Find-Set(u)] <- u;
 for each child v in u in T
   do { TOLCA(v);
        Union(u,v);
        ancestor[Find-Set(u)] <- u;
      }
 colour[u] <- black;
 for each node v such that {u,v} in P
   do if (colour[v] = black) {
      print "Tarjan's Least Common Ancestor of" + u + " and " + v + " is " ancestor[Find-Set(v)];
      }
 }

The following procedure assumes each node is white before coloured black.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Great River, New York

... family size is 3.36. In the town the population is spread out with 29.0% under the age of 18, 5.0% from 18 to 24, 29.0% from 25 to 44, 24.2% from 45 to 64, and 12.7% ...

 
 
 
This page was created in 38.3 ms