Optimal pointer algorithms for finding nearest common ancestors in dynamic trees
We consider the problem of finding the nearest common ancestor of two given nodes x and y (denoted by nca(x, y)) in a dynamic forest of rooted trees. Interspersed with nca-queries are on-line commands link(x, y), where x but not necessarily y is a tree root. The effect of a command link(x, y) is to combine the trees containing x and y by making y the parent of x. This problem was originally proposed by Aho, Hopcroft and Ullman (SIAM J. Comput. 5(1), 115–132, 1976). We present a pointer machine algorithm, which performs n link and m nca in time O(n + m log log n), matching a lower-bound by Harel and Tarjan (SIAM J. Comput. 13(2), 338–355, 1984). The previous best bound on a pointer machine was O((n + m)log n), due to Sleator and Tarjan (J. Comput. Syst. Sc. 26(3), 362–391, 1983).
Unable to display preview. Download preview PDF.
- 1.A.V. Aho, J.E. Hopcroft, and J.D. Ullman. The design and analysis of computer algorithms. Addison-Wesley, 1974.Google Scholar
- 2.A.V. Aho, J.E. Hopcroft, and J.D. Ullman. On finding lowest common ancestor in trees. SIAM Journal on computing, 5(1):115–132, 1976. See also STOC 1973.Google Scholar
- 3.S. Alstrup. Optimal algorithms for finding nearest common ancestors in dynamic trees. Technical Report 95-30, Department of Computer Science, University of Copenhagen, 1995.Google Scholar
- 4.H.N. Gabow. Data structure for weighted matching and nearest common ancestors with linking. In Annual ACM-SIAM Symposium on discrete algorithms (SODA), volume 1, pages 434–443, 1990.Google Scholar
- 5.H.N. Gabow and R.E. Tarjan. A linear-time algorithm for a special case of disjoint set union. Journal of computer and system sciences, 30(2):209–221, 1985.Google Scholar
- 8.R.E. Tarjan. Applications of path compression on balanced trees. Journal of the association for computing machinery (J.ACM), 26(4):690–715, 1979.Google Scholar
- 9.R.E. Tarjan. A class of algorithms which require nonlinear time to maintain disjoint sets. Journal of computer and system sciences, 18(2):110–127, 1979.Google Scholar
- 10.A. K. Tsakalides and J. van Leeuwen. An optimal pointer machine algorithm for finding nearest common ansectors. Technical Report RUU-CS-88-17, Department of Computer Science, University of Utrecht, 1988.Google Scholar
- 11.A.K. Tsakalidis. The nearest common ancestor in a dynamic tree. Acta informatica, 25(1):37–54, 1988.Google Scholar
- 12.J. van Leeuwen. Finding lowest common ancestors in less than logarithmic time. Unpublish technical report, 1976.Google Scholar