Succinct Data Structures

Slides:



Advertisements
Similar presentations
The LCA Problem Revisited Michael A. BenderMartin Farach-Colton Latin American Theoretical Informatics Symposium, pages 8894, Speaker:
Advertisements

Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
5th July 2004CPM A Simple Optimal Representation for Balanced Parentheses Richard Geary, Naila Rahman, Rajeev Raman (University of Leicester, UK)
Lower bound: Decision tree and adversary argument
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Improvements on the Range-Minimum-Query- Problem
1 Chapter 8 Priority Queues. 2 Implementations Heaps Priority queues and heaps Vector based implementation of heaps Skew heaps Outline.
Heapsort Based off slides by: David Matuszek
Introduction n – length of text, m – length of search pattern string Generally suffix tree construction takes O(n) time, O(n) space and searching takes.
The LCA Problem Revisited Michael A.Bender & Martin Farach-Colton Presented by: Dvir Halevi.
COMP20010: Algorithms and Imperative Programming Lecture 4 Ordered Dictionaries and Binary Search Trees AVL Trees.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
The LCA Problem Revisited
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
1Computer Sciences. 2 HEAP SORT TUTORIAL 4 Objective O(n lg n) worst case like merge sort. Sorts in place like insertion sort. A heap can be stored as.
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Sorting Cont. Quick Sort As the name implies quicksort is the fastest known sorting algorithm in practice. Quick-sort is a randomized sorting algorithm.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
CSE 373 Data Structures Lecture 7
"Teachers open the door, but you must enter by yourself. "
Succinct Data Structures
Succinct Data Structures
Succinct Data Structures
Succinct Data Structures
Succinct Data Structures
Succinct Data Structures
Heaps, Heapsort, and Priority Queues
Discrete Methods in Mathematical Informatics
MCS680: Foundations Of Computer Science
Two equivalent problems
Heaps, Heap Sort and Priority Queues
Succinct Data Structures
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Ariel Rosenfeld Bar-Ilan Uni.
Data Structures Review Session 2
Lecture 22 Binary Search Trees Chapter 10 of textbook
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Heap Sort Example Qamar Abbas.
ITEC 2620M Introduction to Data Structures
Introduction to Algorithms
Binary Trees, Binary Search Trees
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
Sorting.
Trees and Binary Trees.
Minimum Spanning Tree Verification
Heaps, Heapsort, and Priority Queues
Algorithms (2IL15) – Lecture 2
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
© 2013 Goodrich, Tamassia, Goldwasser
Discrete Methods in Mathematical Informatics
ICS 353: Design and Analysis of Algorithms
"Teachers open the door, but you must enter by yourself. "
A Robust Data Structure
ICS 353: Design and Analysis of Algorithms
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Topic 5: Heap data structure heap sort Priority queue
HEAPS.
The LCA Problem Revisited
Computer Algorithms CISC4080 CIS, Fordham Univ.
Heaps 9/29/2019 5:43 PM Heaps Heaps.
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

Succinct Data Structures Kunihiko Sadakane National Institute of Informatics

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] 143504537 A 123456789 RMQA(3,6) = 5 RMQA(6,8) = 8

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.

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,i1] Right subtree: the Cartesian tree for A[i+1,n] 143504537 A 1 3 3 4 4 5 5 7

Relation between Cartesian Tree and RMQ RMQA(i,j) = lca(i,j) 143504537 A 1 3 3 4 4 5 5 7

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]

A Property of Cartesian Tree Lemma: If A[n] is added to the Cartesian tree for A[1,n1], 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

Construction of Cartesian Tree When we add A[n] to the tree for A[1,n1] Compare A[n] with elements on the path from A[n1] 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

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).

BP Representation of Cartesian Tree 143504537 A 1 3 3 4 5 4 5 7 P’ 123234543434543212123434543232343210 P ((()((())()(())))()((()(()))()(()))) 1 4 3 5 4 5 3 7

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 123234543434543212123434543232343210 P P’

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 (()((()())())(()())()) 1212343432321232321210 P’ B 1 3 2 1 1

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

Sparse Table Algorithm [2] For each interval [i,i+2k1] 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(bs) Compare M[s, k] and M[b2k+1, k], and output the minimum. O(1) time, O(m lg2 m) bit space 3 143504537 B

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.

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 143504537 A 

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. 143504537 A 7 3 5 4 1  i2 j2 l2 r2 i1 = l1= r1 j1

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 143504537 A  l r i x w y U ((()(())())(()())()) 12323432321232321210 E j

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

Definitions For a vector P[0..2n-1] and a function g RMQ, RMQi are defined similarly (range maximum)

How to support operations on balanced parentheses sequence Lemma: Let  be a function s.t. (() = 1, ()) = 1 (()((()())())(()())()) 1212343432321232321210 P E findclose enclose

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.

References [1] 定兼邦彦, 渡邉大輔. 文書列挙問題に対する実用的なデータ構造. 日本データベース学会Letters Vol.2, No.1, pp.103-106. [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): 12-22 (2007) [4] Johannes Fischer: Optimal Succinctness for Range Minimum Queries. LATIN 2010: 158-169 [5] Kunihiko Sadakane, Gonzalo Navarro: Fully-Functional Succinct Trees. SODA 2010: 134-149. [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.