Download presentation
Presentation is loading. Please wait.
1
Succinct Data Structures
Kunihiko Sadakane National Institute of Informatics
2
Range Minimum Query Problem (RMQ)
Input: array A[1,n] (preprocessing is allowed), interval of indices [i,j] [1,n] Output: the index of a minimum value in sub-array A[i,j] A RMQA(3,6) = 5 RMQA(6,8) = 8
3
A Data Structure for RMQ
Lemma: For an array of length n, let s(n) denote the size of a data structure, and let t(n) denote the time complexity for a query. A data structure satisfying the following formulas can be constructed in O(n) time [1]. Note: the original input array is not used for a query.
4
Cartesian Tree [2] The Cartesian tree for an array A[1,n] consists of
The root note: stores the minimum A[i] in A[1,n] Left subtree: the Cartesian tree for A[1,i1] Right subtree: the Cartesian tree for A[i+1,n] A 1 3 3 4 4 5 5 7
5
Relation between Cartesian Tree and RMQ
RMQA(i,j) = lca(i,j) A 1 3 3 4 4 5 5 7
6
Problem (lca, lowest common ancestor)
Input: a rooted tree T and its two nodes x, y Output: the lowest common ancestor of x, y Known results lca is found in constant time after linear time preprocessing. [Harel, Tarjan SICOMP84] [Schieber, Vishkin SICOMP88] [Bender, Farach-Colton 00]
7
A Property of Cartesian Tree
Lemma: If A[n] is added to the Cartesian tree for A[1,n1], the node for A[n] is on the path from the root to the rightmost leaf. Proof: Because A[n] is the rightmost element in the array, it is never stored in a left-child. 5 3 4 1 4 3 1 5 5 3 4 1 2 5 3 4 1 6 1 2 4 6 3 4 5
8
Construction of Cartesian Tree
When we add A[n] to the tree for A[1,n1] Compare A[n] with elements on the path from A[n1] to the root If an element x smaller than A[n] appears,insert A[n] Let the right child of x the left child of A[n] 4 3 1 5 5 3 4 1
9
Time Complexity Lemma: Cartesian tree is constructed in O(n) time
Proof: Let the number of comparisons to insert A[i] be ci. Then the total time complexity is Each node on the rightmost path of the Cartesian tree becomes the left child of A[i] after the insertion. Therefore it is compared with A[i] only once. This implies that the total number of comparisons is at most 2n. Thus the time complexity is O(n).
10
BP Representation of Cartesian Tree
A 1 3 3 4 5 4 5 7 P’ P ((()((())()(())))()((()(()))()(()))) 1 4 3 5 4 5 3 7
11
Algorithm for RMQ [3] Construct the Cartesian tree for A[1,n]
Convert the Cartesian tree to BP sequence P and depth sequence P’ To find the position m of the leftmost minimum value in A[i,j] i’ = select()(P,i), j’ = select()(P,j) Let m’ be the position of the minimum in P’[i’, j’], then m = rank()(P,m’)+1 ((()((())()(())))()((()(()))()(()))) 1 4 3 5 7 P P’
12
RMQ on P’ Divide P’ into blocks of length w = (lg n)/2
Store minimum values of the blocks in B Minimum value in P’[i’, j’] is either Minimum value in the block containing i’ Minimum value in the block containing j’, or Minimum value in blocks between those blocks P (()((()())())(()())()) P’ B 1 3 2 1 1
13
Complexities Length of P: 4n Length of B: 4n/w = 8n/lg n
RMQ inside a block is done in O(1) time by a table lookup Size of the table Complexities
14
Sparse Table Algorithm [2]
For each interval [i,i+2k1] in array B[1,m], store the minimum value in M[i,k]. ( i = 1 ,...,m , k = 1 ,2, ・・・ ,lg m ) For a given query interval [s,b] Let k = lg(bs) Compare M[s, k] and M[b2k+1, k], and output the minimum. O(1) time, O(m lg2 m) bit space 3 B
15
This data structure is used when the length of B becomes O(n/lg3 n)
⇒o(n) bit space Theorem: RMQ is computed in O(1) time using a 4n+o(n) bit data structure.
16
2n bits Data Structure for RMQ [4]
2d-Min-Heap of array A[1..n] is a tree consisting of nodes v0,…,vn, and the parent vj of vi satisfies j < i A[j] < A[i] A[k] A[i] for all j < k < i Parent value is smaller than child value Child values are sorted in decreasing order 7 3 5 4 1 A
17
If l i, RMQA(i,j) is a child of l and on the path between l and j
Lemma: Let l = lca(i,j). If l = i, RMQA(i,j) = i If l i, RMQA(i,j) is a child of l and on the path between l and j Proof: If l = i, i+1,…, j are descendants of i. From the definition of tree, they are larger than A[i]. If l i, it holds l < i. Children of l are sorted in decreasing order of their values. Thus the rightmost one is the smallest. A 7 3 5 4 1 i2 j2 l2 r2 i1 = l1= r1 j1
18
By using DFUDS U representing 2d-Min-Heap, RMQ is computed as follows.
x = select)(U, i+1) y = select)(U, j) w = RMQE(x, y) if rank)(U, findopen(U, w)) = i return i else return rank)(U, w) i = 3, j = 9 7 3 5 4 1 A l r i x w y U ((()(())())(()())()) E j
19
Range Min-Max Trees [5] In existing succinct data structures for trees, for each operation to be supported, a new index is added. The o(n) term cannot be ignored. The recursive method [6] uses 3.73n bits to support only findopen, findclose, enclose. It is preferable if various operations can be supported by an index
20
Definitions For a vector P[0..2n-1] and a function g
RMQ, RMQi are defined similarly (range maximum)
21
How to support operations on balanced parentheses sequence
Lemma: Let be a function s.t. (() = 1, ()) = 1 (()((()())())(()())()) P E findclose enclose
22
Implementing rank/select
Let , be functions s.t. (0)=0, (1)=1, (0)=1, (1)=0 rank/select and parentheses operations can be handled in a unified manner.
23
References [1] 定兼邦彦, 渡邉大輔. 文書列挙問題に対する実用的なデータ構造. 日本データベース学会Letters Vol.2, No.1, pp [2] Michael A. Bender, Martin Farach-Colton: The LCA Problem Revisited. LATIN 2000: 88-94 [3] Kunihiko Sadakane: Succinct data structures for flexible text retrieval systems. J. Discrete Algorithms 5(1): (2007) [4] Johannes Fischer: Optimal Succinctness for Range Minimum Queries. LATIN 2010: [5] Kunihiko Sadakane, Gonzalo Navarro: Fully-Functional Succinct Trees. SODA 2010: [6] R. F. Geary, N. Rahman, R. Raman, and V. Raman. A simple optimal representation for balanced parentheses. Theoretical Computer Science, 368:231–246, December 2006. [7] Mihai Pătraşcu. Succincter, Proc. FOCS, 2008.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.