Nearly-Optimal Dynamic Subtree Mode

Jialong Zhou, Ben Bals, Sankardeep Chakraborty, Grigorios Loukides, Solon P. Pissis, Kunihiko SadakanearXiv 2026

TL;DR

Finding the most frequent item (the mode) inside a hierarchy—like the most common file type in a directory or the best-selling brand in an e-commerce category—was previously only well-understood for static trees that never change. This paper introduces the first data structures to track subtree modes dynamically as labels change, leaves are added, or entire branches are moved around. Not only do these algorithms hit the theoretical speed limits of computer science, they also crush natural baselines by orders of magnitude in real-world workloads.

What Problem Does This Paper Address?

Imagine managing a massive file system or an e-commerce catalog. Data is naturally organized as a tree, where the leaves carry labels (or "colors," in graph theory speak), such as file extensions or product brands. Asking "what is the most common label in this folder and all its subfolders?" is known as the Subtree Mode (SM) problem.

While computing the mode has been exhaustively studied for 1D arrays (Range Mode) and paths in trees, Subtree Mode had only ever been solved for static trees—structures frozen in time. Real systems aren't frozen: files get renamed, new products are added, and entire folders are dragged and dropped elsewhere.

The authors bridge this gap by defining and tackling two dynamic variants of the problem on a leaf-colored tree of $n$ nodes:

  1. Dynamic Subtree Mode (DSM): The tree's structure is fixed, but leaf colors can be updated.
  2. Fully Dynamic Subtree Mode (FDSM): Leaves can be recolored, inserted, or deleted, and entire subtrees can be cut and linked to new parents.
Figure 1: A tree under successive operations.

Methods

(Note: Because only the cover page, abstract, and table of contents were provided in the document excerpt, internal algorithmic mechanics are summarized at the high level presented in the abstract and outline.)

Unlike sums or minimums, modes are notoriously non-decomposable: knowing the most popular item in Folder A and Folder B tells you nothing about the winner when they are combined (a close runner-up in both might win overall). To tame this without blowing up memory, the authors design linear-space ($O(n)$) data structures tailored to different structural constraints:

  • Smooth Trade-off DSM: After $O(n)$ preprocessing, the authors introduce a parameterized structure controlled by a knob $\alpha \in [0, 1]$. It answers mode queries in $\tilde{O}(n^\alpha)$ time and processes leaf recolorings in $\tilde{O}(n^{1-\alpha})$ time (where $\tilde{O}$ hides logarithmic factors).
  • Height-Sensitive DSM: For shallow trees of height $h$—very common in real-world directory hierarchies—they design a variant that answers queries in $\tilde{O}(1)$ time and updates in $\tilde{O}(h)$ time.
  • Color-Bounded FDSM: When the tree's topology itself can change via link-cut moves, they construct a data structure parameterized by the total number of distinct colors $|\Delta|$. It handles leaf insertions, deletions, and recolorings in $\tilde{O}(1)$ time, while queries and subtree moves take $\tilde{O}(|\Delta|)$ time.
  • Hardness Reductions: To prove they haven't missed a faster trick, the authors pair their upper bounds with conditional lower bounds, reducing from the Online Matrix-Vector Multiplication (OMv) conjecture for DSM and from Dynamic Range Mode for FDSM.

Datasets

Based on the abstract and table of contents, the authors evaluate their structures across multiple domains, including:

  • Standard datasets such as News, Genes-sam (bioinformatics), and WebKB.
  • Real-world case studies using workloads from e-commerce and file systems.

(Detailed dataset statistics and preprocessing steps are located in pages not included in the provided PDF excerpt.)

Key Insights and Ideas

  • Trees are fundamentally easier than arrays—until you move branches: If you flatten a tree into an array (e.g., via an Euler tour), a subtree becomes a 1D range. However, general 1D Dynamic Range Mode is notoriously hard. By exploiting the fixed hierarchy of the tree directly, DSM achieves a smooth $\tilde{O}(n^\alpha)$ vs. $\tilde{O}(n^{1-\alpha})$ trade-off that is conditionally impossible for general 1D arrays!
  • Topology changes bring the hardness right back: Why can't we get that same magical trade-off for Fully Dynamic Subtree Mode? When you allow cutting and linking subtrees, the problem becomes expressive enough to simulate 1D Dynamic Range Mode with only logarithmic overhead—inheriting all of its conditional hardness.
  • Small alphabets save the day in practice: Even though FDSM is theoretically hard in general, many practical applications (like tracking file permission types, status flags, or coarse categories) only use a modest palette of colors $|\Delta|$. Bounding complexity by $|\Delta|$ yields blazing-fast operations despite the theoretical wall.

Key Results

  • Theoretical Optimality: The DSM query/update trade-off of $\tilde{O}(n^\alpha)$ and $\tilde{O}(n^{1-\alpha})$ is proven to be polynomially optimal under the widely believed OMv conjecture.
  • Practical Speedups: Across cross-domain benchmarks and real-world e-commerce and file-system workloads, the proposed DSM and FDSM structures achieve orders-of-magnitude speedups over natural baselines while maintaining linear $O(n)$ space. (Exact wall-clock times and memory footprints are not present in the provided two-page excerpt.)

Limitations and Future Work

While explicit future directions in Section 9 are omitted from the provided excerpt, a primary theoretical limitation established by the authors' own lower bounds is that general FDSM with an unbounded number of colors $|\Delta|$ cannot escape polynomial time bottlenecks due to its equivalence to Dynamic Range Mode. Additionally, the height-sensitive DSM structure relies on the tree height $h$ remaining small; on degenerate, path-like trees where $h = \Theta(n)$, one must fall back to the $\alpha$-trade-off structure.

Summary updated

BibTeX
@misc{zhou2026nearly,
  author = {Jialong Zhou and Ben Bals and Sankardeep Chakraborty and Grigorios Loukides and Solon P. Pissis and Kunihiko Sadakane},
  title = {{Nearly-Optimal Dynamic Subtree Mode}},
  year = {2026},
  eprint = {2611.37616},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.37616},
}
Figure