Arrow Research search
Back to TCS

TCS 2022

Data structures for categorical path counting queries

Journal Article journal-article Computer Science · Theoretical Computer Science

Abstract

Consider an ordinal tree T on n nodes, each of which is assigned a category from an alphabet [ σ ] = { 1, 2, …, σ }. We preprocess the tree T in order to support categorical path counting queries, which ask for the number of distinct categories occurring on the path in T between two query nodes x and y. For this problem, we propose a linear-space data structure with query time O ( n lg ⁡ lg ⁡ σ lg ⁡ w ), where w = Ω ( lg ⁡ n ) is the word size in the word-RAM. As shown in our proof, from the assumption that matrix multiplication cannot be solved in time polynomially faster than cubic (with only combinatorial methods), our result is optimal, save for polylogarithmic speed-ups. For a trade-off parameter 1 ≤ t ≤ n, we propose an O ( n + n 2 t 2 ) -word, O ( t lg ⁡ lg ⁡ σ lg ⁡ w ) query time data structure. We also consider c-approximate categorical path counting queries, which must return an approximation to the number of distinct categories occurring on the query path, by counting each such category at least once and at most c times. We describe a linear-space data structure that supports 2-approximate categorical path counting queries in O ( lg ⁡ n / lg ⁡ lg ⁡ n ) time. Next, we generalize the categorical path counting queries to weighted trees. Here, a query specifies two nodes x, y and an orthogonal range Q. The answer to thus formed categorical path range counting query is the number of distinct categories occurring on the path from x to y, if only the nodes with weights falling inside Q are considered. We propose an O ( n lg ⁡ lg ⁡ n + ( n / t ) 4 ) -word data structure with O ( t lg ⁡ lg ⁡ n ) query time, or an O ( n + ( n / t ) 4 ) -word data structure with O ( t lg ϵ ⁡ n ) query time. For an appropriate choice of the trade-off parameter t, this implies a linear-space data structure with O ( n 3 / 4 lg ϵ ⁡ n ) query time. We then extend the approach to the trees weighted with vectors from [ n ] d, where d is a constant integer greater than or equal to 2. We present a data structure with O ( n lg d − 1 + ϵ ⁡ n + ( n / t ) 2 d + 2 ) words of space and O ( t lg d − 1 ⁡ n ( lg ⁡ lg ⁡ n ) d − 2 ) query time. For an O ( n ⋅ polylog n ) -space solution, one thus has O ( n 2 d + 1 2 d + 2 ⋅ polylog n ) query time. The inherent difficulty revealed by the lower bound we proved motivated us to consider data structures based on sketching. In unweighted trees, we propose a sketching data structure to solve the approximate categorical path counting problem which asks for a ( 1 ± ϵ ) -approximation (i. e. within 1 ± ϵ of the true answer) of the number of distinct categories on the given path, with probability 1 − δ, where 0 < ϵ, δ < 1 are constants. The data structure occupies O ( n + n t lg ⁡ n ) words of space, for the query time of O ( t lg ⁡ n ). For trees weighted with d-dimensional weight vectors ( d ≥ 1 ), we propose a data structure with O ( ( n + n t lg ⁡ n ) lg d ⁡ n ) words of space and O ( t lg d + 1 ⁡ n ) query time. All these problems generalize the corresponding categorical range counting problems in Euclidean space R d + 1, for respective d, by replacing one of the dimensions with a tree topology.

Authors

Keywords

  • Data structures
  • Weighted trees
  • Path queries
  • Categorical queries
  • Colored queries
  • Categorical path counting
  • Categorical path range counting

Context

Venue
Theoretical Computer Science
Archive span
1975-2026
Indexed papers
16261
Paper id
383460078238439556
v2026.09.13