Succinct Representation of Balanced Parentheses, Static Trees and Planar Graphs J. Ian Munro & Venkatesh Raman.

Slides:



Advertisements
Similar presentations
Space-Efficient Static Trees and Graphs Guy Jacobson IEEE Symposium on Foundations of Computer Science, 1989 Speaker: 吳展碩.
Advertisements

1 Succinct Representation of Labeled Graphs Jérémy Barbay, Luca Castelli Aleardi, Meng He, J. Ian Munro.
Two Segments Intersect?
Succinct Data Structures for Permutations, Functions and Suffix Arrays
2/14/13CMPS 3120 Computational Geometry1 CMPS 3120: Computational Geometry Spring 2013 Planar Subdivisions and Point Location Carola Wenk Based on: Computational.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Graph Isomorphism Algorithms and networks. Graph Isomorphism 2 Today Graph isomorphism: definition Complexity: isomorphism completeness The refinement.
Introduction to Trees Chapter 6 Objectives
A New Compressed Suffix Tree Supporting Fast Search and its Construction Algorithm Using Optimal Working Space Dong Kyue Kim 1 andHeejin Park 2 1 School.
Succinct Data Structures Ian Munro University of Waterloo Joint work with David Benoit, Andrej Brodnik, D, Clark, F. Fich, M. He, J. Horton, A. López-Ortiz,
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
Transforming Infix to Postfix
1 Separator Theorems for Planar Graphs Presented by Shira Zucker.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Compact Representations of Separable Graphs From a paper of the same title submitted to SODA by: Dan Blandford and Guy Blelloch and Ian Kash.
Important Problem Types and Fundamental Data Structures
Binary and Other Trees CSE, POSTECH. 2 2 Linear Lists and Trees Linear lists are useful for serially ordered data – (e 1,e 2,e 3,…,e n ) – Days of week.
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan.
Randomized Algorithms - Treaps
Mike 66 Sept Succinct Data Structures: Techniques and Lower Bounds Ian Munro University of Waterloo Joint work with/ work of Arash Farzan, Alex Golynski,
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
COSC2007 Data Structures II
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Succinct Representations of Trees
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
“On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra.
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
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.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
S EARCHING AND T REES COMP1927 Computing 15s1 Sedgewick Chapters 5, 12.
Section 10.1 Introduction to Trees These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 6 th ed., by Kenneth.
Summer School '131 Succinct Data Structures Ian Munro.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Succinct Data Structures Ian Munro University of Waterloo Joint work with David Benoit, Andrej Brodnik, D, Clark, F. Fich, M. He, J. Horton, A. López-Ortiz,
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Data Structures Balanced Trees CSCI 2720 Spring 2007.
Succinct Data Structures
Succinct Data Structures
Top 50 Data Structures Interview Questions
Succinct Data Structures
Chapter 5 : Trees.
Algorithms and networks
TREES General trees Binary trees Binary search trees AVL trees
The Art Gallery Problem
Discrete Methods in Mathematical Informatics
Succinct Representation of Labeled Graphs
Trees.
Important Problem Types and Fundamental Data Structures
Presentation transcript:

Succinct Representation of Balanced Parentheses, Static Trees and Planar Graphs J. Ian Munro & Venkatesh Raman

Outline Introduction Balanced Parentheses Static Trees –Rooted Ordered Tree –Binary Trees Planar Graphs Balanced Parentheses Implementation

Problem We would like to represent tree with minimal number of bits, permitting the regular operations in constant time.

Information limit Number of trees on n nodes: or about. So, at least 2n bits needed ( ignoring logarithmic terms ) to encode an arbitrary tree.

2n bit representation Do a preorder traversal of the tree –if visit a node for a first time – output “(“ –if visit a node for a last time – output “)” We got a balanced nested parenthesis sequence.

Example ( ( ( ) ( ) ) ( ) ( ) )

Balanced Parentheses Operations findclose(i) findopen(i) excess(i) - find the difference of the number of open and close parentheses at position i. enclose(i) - given a parenthesis pair, opened at position i, find its closest enclosing matching parenthesis pair. We will see there implementation in constant time using 2n+o(n) bits … O(1)

Static Trees – Rooted Ordered Tree We use isomorphism between general ordered trees and balanced parenthesis expressions as was described earlier. Node represented by its corresponding left parenthesis.

Rooted Ordered Tree ( Cont.) parent(i) - is a left parenthesis of enclose(i) size of subtree(i) – all nodes between i and findclose(i), number of nodes is half a difference between them ( ( ( ) ( ) ) ( ) ( ) ) parent (3): subtree (2):

Rooted Ordered Tree(Cont) The i-th child of node x: ( ( ( ) ( ) ) ( ) ( ) ) if the parenthesis next to x’s “(“ is “)”, than x has no children. otherwise “(“ and its matching “)” form the first child. if the next parenthesis is “(“ together with matching parenthesis match the second child of x and so on... ( ( ( ) ( ) ) ( ) ( ) ) ( ( ( ) ( ) ) ( ) ( ) ) ( ( ( ) ( ) ) ( ) ( ) )

General ordered tree - conclusion We can find: parent, size of subtree in O(1) right (first) or left(last) son of node x in O(1). i-th child of x in O(i) using 2n+o(n) bits

Static Trees – Binary trees Q: For a node that has only one child, how we can distinct is it right or left son ? A: Use isomorphism between binary trees and rooted ordered trees. ( ( ) )

Isomorphism example Binary Tree Equivalent Rooted Ordered Tree

Binary trees ( cont. ) Ordered root has a root which doesn’t correspond to any node in the binary tree. The left child in the binary is the leftmost child in the ordered tree. The right child in the binary is the next sibling to the right in the ordered tree. The root of the binary is the leftmost child of the root of the ordered tree.

Example – parent(i) ( ( ( ( ) ) ( ) ) ) ( ( ) ) ( ) ( ) ) ( ) ) parent 2parent Binary Tree

Example – subtree(i) ( ( ( ( ) ) ( ) ( ) ) ( ) ) subtree 2: right subtreeleft subtree Binary Tree enclose 2

Binary trees ( cont. ) For a given left parenthesis of node x at position i:  parent :  if i = 1 no parent ( root)  if symbol at position i-1 is “(“ than it its parent  else findopen(i-1) is its parent.  left child : if symbol at position i+1 is “(“.  right child : if symbol at position findclose(i)+1 is “(“.  subtree : all nodes in the subtree and its right siblings.

Binary tree - conclusions We can find: parent, size of subtree, left and right child in O(1) using 2n+o(n) bits

Planar graphs Definition : A k-page book embedding of a graph G=(V,E) is a printing order of V, plus a partition of E into k pages. The edges on a given page must not intersect. Planar graphs can be embedded in four pages.

One-Page Graphs - example () (( () )( () (( () ) () ))( () ))( () ) Parenthesis representation uses 2n+2m bits

adjacent(i,j) - example () (( () )( () (( () ) () ))( () ))( () )

adjacent(i,j) – cont. () )))) ((( () ))).... () excess i excess i+1 #closed#opened #closed + #opened = degree(i) #closed - #opened = excess i – excess i+1 First open parenthesis of i: j

One-Page Graphs ( cont. ) Given node i, we can find node i+1 in O(1) ; given edge, we can find node it belongs to in O(1) using o(n) extra space ( using rank, select operations - won’t be shown here ).

One-Page Graphs ( cont. ) degree(i) – difference indices between nodes i and i+1. adjacent( i, j) – find the matching parenthesis of the first open parenthesis after the pair corresponding to vertex i. if its index less than j, adjacent(i,j)=false, otherwise find the matching parenthesis of the last close parenthesis after the pair corresponding to vertex j.If it corresponds to i, adjacent(i,j ) = true.

One-Page Graphs - conclusion Can be represented using 2n+2m+o(n+m) bits. Adjacency of a pair of vertices, the degree of any given vertex can be found in O(1), the neighbors of a vertex i can be produced in O( degree(i) ) time.

Graph with more than one page Represent each page separately, share the same order of vertices. If the graph has k pages, a vertex requires 2k bits whereas an edge 2 bits. The parenthesis representation requires 2nk + 2m bits. Adjacency of a pair of vertices, the degree of any given vertex can be found in O(k), the neighbors of a vertex i can be produced in O( degree(i) + k ) time.

Planar graphs - conclusions Space requirement is at most: 8n+m+o(m+n) = 14n+o(n), since m is at most 3n. Time performance is like one–page graphs.

Balanced Parentheses – implementation in 2n+o(n) Theorem: Given a nested string of 2n balanced parentheses, using o(n) auxiliary bits we can perform the operations: findclose(i), findopen(i), excess(i) and enclose(i) in constant time.

Proof: Divide sequence to blocks: big block small block... big block... small block

Definition far parenthesis – if its matching parenthesis lies outside its block far parenthesis is a pioneer if its matching parenthesis lies in a different block than that of the previous far parenthesis in the sequence. ( ( () ( ) ) ( ) far pioneer

Proof: Imagine a graph with a node for each block. Create an edge between blocks if there is pioneer between them. None of the edges can cross. No double edges. We got outer-planar graph, one of its properties that it has at most 2b – 3 edges. Theorem: The number of pioneers in b blocks is at most 2b – 3.

With each pioneer parenthesis we keep address of its matching parenthesis. Space requirement:

findclose(i) – for far parenthesis Given left far parenthesis, find its excess and its preceding pioneer Given pioneer, find far parenthesis target block. Given target block, find first close parenthesis with the same right excess.

Intuition – step 1 :... big block... small block #big blocks = #small blocks =

Storing with each big block head: the position of the immediately preceding pioneer (to its left) in big block. excess in binary ( (#0 - #1) up to that position) – value between (0 -n).

Storing with each small block head: the position of the immediately preceding pioneer ( and 0 if there is no pioneer ). the excess in binary ( starting from the big block head ) at that position. a bit indicating whether there is a pioneer in the small block. and...

Storing all possible small blocks: a bitmap of pioneers in the small block if the small block contains a pioneer. number of possible small blocks: for each entries of size bits storing previous pioneer index.

Find the preceding pioneer address for a far parenthesis. Given i, check if its small block has pioneer. if yes, consult bitmap if exist pioneer before i. if not, the small block header or the big block header will give the address. Analogous strategy is to find excess of far parenthesis at the given position...

Once we find the preceding pioneer parenthesis of a given far, we know the target big block of the given parenthesis from pioneer information. Given left far parenthesis, find its excess and its preceding pioneer Given pioneer, find far parenthesis target block.

Given left far parenthesis, find its excess and its preceding pioneer Given pioneer, find far parenthesis target block. Given target block, find first close parenthesis with the same right excess.

Looking for a first parenthesis with excess e in a given block excess within a big block is at most. store a table for every excesses. excess place i j (i<j) k (j<k)... #big blocks #table entries size of entry Table complexity:

Looking for a first parenthesis with excess e in a given block ( cont.) for two consecutive entries in table: if ( j – i > lg n / 2 ) keep all entries number such portions Space requirement:

Looking for a first parenthesis with excess e in a given block ( cont.) for two consecutive entries in table: if ( j – i <= log n / 2 ) keep table of answers. #of possible strings for each excess value Space requirement:

We can find the matching closing parenthesis for a far open parenthesis using o(n) bits of extra storage in O(1). We also can find the excess value at every far position at constant time.

What about not far parenthesis ? Use exactly the same strategy for far parenthesis with respect to the small blocks within the big block. small block tiny block

Q:What about not far parenthesis inside small block ? A:Table of answers  For every possible string of small block ( of length ) and for every position in that string create a table entry.  In each entry two values:  excess in binary  next one or previous zero or none of them. Space: o(n)

What we have done ? findclose(i) findopen(i) excess(i)  enclose(i)

enclose(i) e = excess(i) Look for right parenthesis with e-1 in a target block of closing parenthesis. What if its not in that block ? With every block header we keep a pointer to the parenthesis that has right excess one less that the minimum at that block.

Conclusions Parentheses representation in 2n+o(n) with findclose(i), findopen(i), excess(i), enclose(i) in constant time. Static trees representation in 2n+o(n) that can find parent, left child, right child, size of the subtree in constant time. Planar graph representation in 8n+ 2m + o(m + n) that can answer adjacent, degree in constant time, give all neighbors in O(degree ) time.