Fast and simple unrooted dynamic forests
Benjamin Aram Berendsohn
TL;DR
This work introduces dynamic forests built on search trees on trees (STTs), focusing on unrooted forests where traditional link-cut trees (LCTs) are less competitive. It formalizes 2-cut STTs, provides explicit, constant-time rotations, and implements Link, Cut, and PathWeight via a NodeToRoot primitive with multiple variants of NodeToRoot (MoveToRootTT and several SplayTT variants). The authors present a modular Rust library that compares STT-based methods against LCTs, showing that STT-based approaches excel on unrooted forests while LCTs remain faster for rooted forests; among STT variants, Greedy SplayTT often offers the best practical performance. The results demonstrate the practicality and competitiveness of STT-based dynamic forests, highlighting their simpler rotation primitive and potential advantages in unrooted settings, with open questions around further optimizations and real-world applications.
Abstract
A dynamic forest data structure maintains a forest (and associated data like edge weights) under edge insertions and deletions. Dynamic forests are widely used to solve online and offline graph problems. Well-known examples of dynamic forest data structures are link-cut trees [Sleator and Tarjan '83] and top trees [Alstrup, Holm, de Lichtenberg, and Thorup '05], both of which need O(log n) time per operation. While top trees are more flexible and arguably easier to use, link-cut trees are faster in practice [Tarjan and Werneck '10]. In this paper, we propose an alternative to link-cut trees. Our data structure is based on search trees on trees (STTs, also known as elimination trees) and an STT algorithm [Berendsohn and Kozma '22] based on the classical Splay trees [Sleator and Tarjan '85]. While link-cut trees maintain a hierarchy of binary search trees, we maintain a single STT. Most of the complexity of our data structure lies in the implementation of the STT rotation primitive, which can easily be reused, simplifying the development of new STT-based approaches. We implement several variants of our data structure in the Rust programming language, along with an implementation of link-cut trees for comparison. Experimental evaluation suggests that our algorithms are faster when the dynamic forest is unrooted, while link-cut trees are faster for rooted dynamic forests.
