paper

Nearly-Optimal Dynamic Subtree Mode

arXiv:2611.37616

Abstract

Computing the mode (i.e., the most frequent element) in a range of an array, or in a path of a colored tree, has been studied extensively in both the static and dynamic setting. However, the problem of computing the mode in a subtree of a leaf-colored tree, referred to as the Subtree Mode (SM), has only been studied in the static setting, despite its applications in domains ranging from file systems, to e-commerce, and bioinformatics. Here, we study the SM problem as the tree undergoes changes. We define Dynamic Subtree Mode (DSM), which asks for a data structure supporting leaf recolorings in a fixed tree, and Fully Dynamic Subtree Mode (FDSM), which additionally supports leaf insertions and deletions and subtree moves. For DSM on a tree of nodes, we propose a linear-space data structure with preprocessing and, for any , query and update times and , respectively. This trade-off is polynomially optimal under the Online Matrix-Vector Multiplication conjecture. For trees of height , query and update times improve to and , respectively. For FDSM, a logarithmic-overhead reduction from Dynamic Range Mode gives a conditional lower bound. For a color set , we obtain a linear-space data structure supporting queries and subtree moves in time and recolorings and leaf insertions and deletions in time. Thus, while DSM exploits the tree structure to achieve query-update trade-offs that are conditionally impossible for Dynamic Range Mode, FDSM inherits its conditional hardness but admits efficient solutions when is small. Experiments on datasets from different domains, as well as case studies using workloads from e-commerce and file systems, show speedups of orders of magnitude over natural baselines.