Abstract

We start a systematic study of data structures for the nearest colored node problem on trees. Given a tree with colored nodes and weighted edges, we want to answer queries (v,c) asking for the nearest node to node v that has color c. This is a natural generalization of the well-known nearest marked ancestor problem. We give an O(n)-space O(log⁡log⁡n)-query solution and show that this is optimal. We also consider the dynamic case where updates can change a node's color and show that in O(n) space we can support both updates and queries in O(log⁡n) time. We complement this by showing that O(polylogn) update time implies Ω(log⁡nlog⁡log⁡n) query time. Finally, we consider the case where updates can change the edges of the tree (link-cut operations). There is a known (top-tree based) solution that requires update time that is roughly linear in the number of colors. We show that this solution is probably optimal by showing that a strictly sublinear update time implies a strictly subcubic time algorithm for the classical all pairs shortest paths problem on a general graph. We also consider versions where the tree is rooted, and the query asks for the nearest ancestor/descendant of node v that has color c, and present efficient data structures for both variants in the static and the dynamic setting.

Highlights

  • We consider a number of problems on trees with colored nodes

  • This holds even when the number of colors is only two. We show that this lower bound extends to both the nearest colored node and the nearest colored descendant

  • We show that the nearest colored node problem can be solved with O(n)-space, O(log n)-update, and O(log n)-query

Read more

Summary

Introduction

We consider a number of problems on trees with colored nodes. Each of these problems can be either static, meaning the color of every node of a tree T on n nodes is fixed, or dynamic, meaning that an update can change a node’s color (but the tree itself does not change). We show that the nearest colored node problem can be solved with O(n)-space, O(log n)-update, and O(log n)-query. The original top-trees of Alstrup-Holm-de Lichtenberg-Thorup [2] were designed for only two colors (i.e., for the nearest marked node problem) They achieve O(log n) query and update and support updates that insert and delete edges (i.e., maintain a forest under link-cut operations). A predecessor structure is a data structure that stores a set of n integers S ⊆ [0, U ], so that given x ∈ [0, U ] we can determine the largest y ∈ S such that y ≤ x It is known [15] that for U = n2 any predecessor structure of O(n polylog n)-space requires Ω(log log n)-query, and that linear-size structures with such query-time exist [16, 18]. There exists O(n)-space, O(1)-query perfect hash structure [10], which can be made dynamic with O(1)-update (expected amortized) [9]

Static Upper Bounds
Dynamic Upper Bounds
Lower Bounds
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call