Today we used the fact that we could preprocess a tree in linear time, so that we could answer least-common ancestor (LCA) queries on constant time. This was a theorem of Harel and Tarjan.

However, suppose we are given the and a list of pairs , and we want to output the list of LCAs of the pairs . **Exercise:** *do this in time using the union-find algorithm as a black-box.*

Note that the running time of this approach is worse than Harel and Tarjan, and moreover we have to give the entire list of pairs up-front, so it’s batch processing instead of the queries arriving online. That’s why it’s a (medium hardness) exercise.

Two other comments. Re Ackermann functions, here’s the formal definition of the function, as well as the definition of the particular inverse form used in most papers. The theorem says that on any sequence of unions and makesets, and finds, the data structure takes time.

Lastly: I will put up a scan of my handwritten notes on the webpage soon, e.g., with details of why the sum is O(m+n). [Update: posted.]

### Like this:

Like Loading...

*Related*