Succinct data structures for nearest colored node in a tree

https://doi.org/10.1016/j.ipl.2017.10.001Get rights and content

Highlights

  • We give a data-structure that stores a tree with colors on the nodes. Given a node x and a color α, the structure finds the nearest node to x with color α.

  • The structure is succinct, namely its space complexity is very near to the optimal space required to store the tree.

  • This structure improves the O(nlogn)-bits structure.

Abstract

We give succinct data structures that store a tree with colors on the nodes. Given a node x and a color α, the structures find the nearest node to x with color α. Our results improve the O(nlogn)-bits structure of Gawrychowski et al. (2016) [12].

Introduction

In the nearest colored node problem the goal is to store a tree with colors on the nodes such that given a node x and a color α, the nearest node to x with color α can be found efficiently. Gawrychowski et al. [12] gave a data structure for this problem that uses O(nlogn) bits and answers queries in O(loglogn) time, where n is the number of nodes in the tree.

In this paper we give succinct structures for the nearest colored node problem. Our results are given in the following theorem.

Theorem 1

Let T be a colored tree with n nodes and colors from [1,σ], and let PT be a string containing the colors of the nodes in preorder.

  • 1.

    For σ=o(logn/(loglogn)2), for any k=o(logn/log2σ), there is a representation of T that uses nHk(PT)+2n+o(n) bits and answers nearest colored node queries in O(1) time, where Hk(PT) is the k-th order entropy of PT.

  • 2.

    For σ=wO(1) (where w is the word size), for any function f(n)=ω(1), there is a representation of T that uses nH0(PT)+2n+o(n) bits and answers nearest colored node queries in O(f(n)) time.

  • 3.

    For σn, there is a representation of T that uses nH0(PT)+2n+o(nH0(PT))+o(n) bits and answers nearest colored node queries in O(loglogσlogw) time.

Theorem 1 improves both the space complexity and the query time complexity of the structure of Gawrychowski et al. [12].

Gawrychowski et al. [12] also considered a dynamic version of the nearest colored node problem in which the colors of the nodes can be changed. For this problem they gave an O(nlogn) bits structure that supports updates and queries in O(logn) time. They also gave a structure with O(nlog2+ϵn) space, optimal O(logn/loglogn) query time, and O(log1+ϵn) update time.

Several papers studied data structures for storing colored trees with support for various queries [4], [6], [9], [13], [14], [19], [20]. In particular, the problem of finding the nearest ancestor with color α was considered in [6], [13], [14], [19], [20]. In order to solve the nearest colored node problem, we combine techniques from the papers above and from Gawrychowski et al. [12].

Another related problem is to find an approximate nearest node with color α. This problem has been studied in general graphs [7], [15], [16] and planar graphs [1], [17], [18].

Section snippets

Preliminaries

Throughout the paper we assume the tree T is an ordinal tree (for a non-ordinal tree an ordering can be chosen arbitrarily). When we write that a node w is a descendant of v it means that either w=v or w is a proper descendant of v. The same holds for other tree terminology, e.g. ancestor.

A node with color α will be called α-node. We also use other α-terms with the appropriate meaning, e.g. an α-descendant of a node v is a descendant of v with color α.

Proof of part 1 of Theorem 1

Our structure is similar to the labeled tree structure of He et al. [14]. As in [14], the data structure stores PT in the compressed structure of Ferragina and Venturini [10], the tree T without the colors in the data structure of Farzan and Munro [8], and additional structures described below. Recall that the structure of T keeps the balanced parenthesis string of T.

Using the tree decomposition of Lemma 2, the tree T is partitioned into mini-trees of size at most L=log2n, and every

Proof of parts 2 and 3 of Theorem 1

Our data structure stores the rank-select structure of Belazzougui and Navarro [5] on PT, the tree structure of Farzan and Munro [8] on the tree T without the colors, and additional information that will be described below.

Our structure is similar to the structure of Gawrychowski et al. [12]. We next give a short description of the structure of [12]. For a color α, let Zα be the set of all α-nodes and their ancestors, and let Yα be the set of all nodes xZα such that either x has color α, or x

References (20)

There are more references available in the full text version of this article.
View full text