Lecture #2

Today we used the fact that we could preprocess a tree $T$ 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 $T$ and a list of $m$ pairs $(u_i, v_i)$, and we want to output the list of LCAs of the pairs $(u_i, v_i)$. Exercise: do this in $O(m \alpha(m,n))$ 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 $\alpha(m,n)$ used in most papers. The theorem says that on any sequence of $n$ unions and makesets, and $m$ finds, the data structure takes $O(n + m \alpha(m,n))$ 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.]