1 Nearest Commen Ancestors (NCA) Discrete Range Maximum 1234567891011 4716 6213583 4 7 1 6 11 6 8 2 35 Cartesian Tree [Vuillemin 1980] i j max(i, j) i.

Slides:



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

Fast Algorithms for Finding Nearest Common Ancestors Dov Harel and Robert Endre Tarjan Fast Algorithms for Finding Nearest Common Ancestors SIAM J. COMPUT.
Gerth Stølting Brodal University of Aarhus Monday June 9, 2008, IT University of Copenhagen, Denmark International PhD School in Algorithms for Advanced.
1 Suffix Arrays: A new method for on-line string searches Udi Manber Gene Myers May 1989 Presented by: Oren Weimann.
Suffix Trees Construction and Applications João Carreira 2008.
Two implementation issues Alphabet size Generalizing to multiple strings.
Suffix Sorting & Related Algoritmics Martin Farach-Colton Rutgers University USA.
© 2004 Goodrich, Tamassia Tries1. © 2004 Goodrich, Tamassia Tries2 Preprocessing Strings Preprocessing the pattern speeds up pattern matching queries.
Suffix Trees Suffix trees Linearized suffix trees Virtual suffix trees Suffix arrays Enhanced suffix arrays Suffix cactus, suffix vectors, …
The Trie Data Structure Basic definition: a recursive tree structure that uses the digital decomposition of strings to represent a set of strings for searching.
Tries Search for ‘bell’ O(n) by KMP algorithm O(dm) in a trie Tries
A Linear Time Algorithm for the k Maximum Sums Problem By Gerth S. Brodal and Allan G. Jørgensen.
Suffix Trees String … any sequence of characters. Substring of string S … string composed of characters i through j, i ate is.
Update 1 Persistent Data Structures (Version Control) v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Ephemeral query v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Partial persistence.
Lowest common ancestors. Write an Euler tour of the tree LCA(1,5) = 3 Shallowest node.
Binary Trees A binary tree is made up of a finite set of nodes that is either empty or consists of a node called the root together with two binary trees,
Suffix trees and suffix arrays presentation by Haim Kaplan.
6/26/2015 7:13 PMTries1. 6/26/2015 7:13 PMTries2 Outline and Reading Standard tries (§9.2.1) Compressed tries (§9.2.2) Suffix tries (§9.2.3) Huffman encoding.
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.
Improvements on the Range-Minimum-Query- Problem
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
Hideo Bannai, Shunsuke Inenaga, Masayuki Takeda Kyushu University, Japan SPIRE Cartagena, Colombia.
Computer Science and Software Engineering University of Wisconsin - Platteville 12. Heap Yan Shi CS/SE 2630 Lecture Notes Partially adopted from C++ Plus.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
© 2004 Goodrich, Tamassia Tries1. © 2004 Goodrich, Tamassia Tries2 Preprocessing Strings Preprocessing the pattern speeds up pattern matching queries.
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
Sorting with Heaps Observation: Removal of the largest item from a heap can be performed in O(log n) time Another observation: Nodes are removed in order.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
Data Structures and Algorithms Lecture (BinaryTrees) Instructor: Quratulain.
DATA STRUCTURES Queues ‘n Stacks Tries, Suffix Trees Heaps Sieve of Eratosthenes.
The LCA Problem Revisited
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
Constant-Time LCA Retrieval Presentation by Danny Hermelin, String Matching Algorithms Seminar, Haifa University.
Tries1. 2 Outline and Reading Standard tries (§9.2.1) Compressed tries (§9.2.2) Suffix tries (§9.2.3)
Suffix trees. Trie A tree representing a set of strings. a b c e e f d b f e g { aeef ad bbfe bbfg c }
HEAPS Amihood Amir Bar Ilan University Sorting Bubblesort: Until no exchanges: For i=1 to n-1 if A[i]>A[i+1] then exchange their values end Time.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
Everything is String. Closed Factorization Golnaz Badkobeh 1, Hideo Bannai 2, Keisuke Goto 2, Tomohiro I 2, Costas S. Iliopoulos 3, Shunsuke Inenaga 2,
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
Main Index Contents 11 Main Index Contents Complete Binary Tree Example Complete Binary Tree Example Maximum and Minimum Heaps Example Maximum and Minimum.
1 Nearest Common Ancestors (NCA) Discrete Range Maximum Cartesian Tree [Vuillemin 1980] i j max(i, j) i.
3/12/2013Computer Engg, IIT(BHU)1 PRAM ALGORITHMS-3.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
Advanced Data Structures Lecture 8 Mingmin Xie. Agenda Overview Trie Suffix Tree Suffix Array, LCP Construction Applications.
Succinct Data Structures
Tries 4/16/2018 8:59 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Tries 07/28/16 11:04 Text Compression
Tries 5/27/2018 3:08 AM Tries Tries.
List Order Maintenance
Two equivalent problems
Binary search tree. Removing a node
Andrzej Ehrenfeucht, University of Colorado, Boulder
Persistent Data Structures (Version Control)
Ariel Rosenfeld Bar-Ilan Uni.
Tries 9/14/ :13 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Strings: Tries, Suffix Trees
Minimum Spanning Tree Verification
Reporting (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of the from: Given an interval I=[x1,x2]
Lecture 19-Problem Solving 4 Incremental Method
Suffix trees.
Tries 2/23/2019 8:29 AM Tries 2/23/2019 8:29 AM Tries.
Suffix Trees String … any sequence of characters.
Tries 2/27/2019 5:37 PM Tries Tries.
Suffix Arrays and Suffix Trees
Aggregate-Max Nearest Neighbor Searching in the Plane
X y y = x2 - 3x Solutions of y = x2 - 3x y x –1 5 –2 –3 6 y = x2-3x.
Dynamic Programming II DP over Intervals
Discrete Range Maximum
Presentation transcript:

1 Nearest Commen Ancestors (NCA) Discrete Range Maximum Cartesian Tree [Vuillemin 1980] i j max(i, j) i j nca(i, j) Preprocessing Time vs Query Time ? Org. [D. Harel, R.E. Tarjan, Fast algorithms for finding nearest common ancestors, SIAM J. on Comp. 13 (2): 338–355, 1984]

 Incremental construction left-to-right  O(n) time 2 Cartesian Tree Construction 18∙∙∙13∙∙∙ START HERE

A B C D E F J G KI 3 Reduction: NCA  Discrete Range Maximum Euler Tour HEBABDCDBEFGFEHJIJKJH node depth i j nca(i, j) E G C ji 2 minimum depth nca(i, j) H

4 NCA on Perfect Binary Trees i 2i2i2i = nca(11,21) 11 = = nca(21,21) = 5 = = lcp( , ) longest common prefix proc lcp(x, y) if y < x then swap (x, y) return x >> (msb(x XOR (y >> (msb(y)-msb(x))) position of most significant bit ≠ 0

5 Discrete Range Mimimum - O(n∙log n) Space d j 0 1 i ∙ ∙ ∙ right i left j drm(i, j) = min(right i (d), left j (d)) d = msb(i XOR j) nca(i, j)

6 Blocked solution – O(n) space block of O(log n) elements j i W j (One for each j) Block query: j+1-msb(W j AND ((1 << (j-i+1))-1)) General query: 1 top query + 2 bottom queries Top structure O(n/log n) elements Space O(n) Query O(1) O(n) Preprocessing Time O(1) Query Time

7 Summary... General Discrete Range Searching Cartesian Tree NCA Discrete Range Max on Depth Array ”O(n∙log n)” solution on O(n/log n) blocks O(log n) size blocks i j i j nca(i, j) O(n) Preprocessing Time O(1) Query Time

 Preprocess a string  Query Length of longest common substring starting a positions i and j 8 An NCA application TATTATTAA$ j i nca(i, j) TATTATTAA$ i j Build suffix tree + NCA query Suffix tree