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

Slides:



Advertisements
Similar presentations
Problems and Their Classes
Advertisements

Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
Garfield AP Computer Science
Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of.
Efficient Keyword Search for Smallest LCAs in XML Database Yu Xu Department of Computer Science & Engineering University of California, San Diego Yannis.
Optimal PRAM algorithms: Efficiency of concurrent writing “Computer science is no more about computers than astronomy is about telescopes.” Edsger Dijkstra.
Analysis of Algorithms
Fast Algorithms For Hierarchical Range Histogram Constructions
1 Suffix Arrays: A new method for on-line string searches Udi Manber Gene Myers May 1989 Presented by: Oren Weimann.
QuickSort Average Case Analysis An Incompressibility Approach Brendan Lucier August 2, 2005.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
Algorithm Design Techniques: Divide and Conquer. Introduction Divide and conquer – algorithm makes at least two recursive calls Subproblems should not.
Constant-Time LCA Retrieval
Suffix Sorting & Related Algoritmics Martin Farach-Colton Rutgers University USA.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
1 Nearest Commen Ancestors (NCA) Discrete Range Maximum Cartesian Tree [Vuillemin 1980] i j max(i, j) i.
IP Address Lookup for Internet Routers Using Balanced Binary Search with Prefix Vector Author: Hyesook Lim, Hyeong-gee Kim, Changhoon Publisher: IEEE TRANSACTIONS.
Lowest Common Ancestors Two vertices (u, v) Lowest common ancestors, lca (u, v) Example lca (5, 6) = 4 lca (3, 7) = 2 lca (7, 8) = 1 l(v):
Binary Search Visualization i j.
Lowest common ancestors. Write an Euler tour of the tree LCA(1,5) = 3 Shallowest node.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
1 11/27/06CS150 Introduction to Computer Science 1 Searching Arrays.
Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
Improvements on the Range-Minimum-Query- Problem
1 Efficiency of Algorithms. 2  Two main issues related to the efficiency of algorithms:  Speed of algorithm  Efficient memory allocation  We will.
Solution methods for Discrete Optimization Problems.
Basic PRAM algorithms Problem 1. Min of n numbers Problem 2. Computing a position of the first one in the sequence of 0’s and 1’s.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
CIS 068 Welcome to CIS 068 ! Lesson 9: Sorting. CIS 068 Overview Algorithmic Description and Analysis of Selection Sort Bubble Sort Insertion Sort Merge.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 8 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
The LCA Problem Revisited Michael A.Bender & Martin Farach-Colton Presented by: Dvir Halevi.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
The LCA Problem Revisited
Bucket & Radix Sorts. Efficient Sorts QuickSort : O(nlogn) – O(n 2 ) MergeSort : O(nlogn) Coincidence?
Constant-Time LCA Retrieval Presentation by Danny Hermelin, String Matching Algorithms Seminar, Haifa University.
Collection Depots Facility Location Problems in Trees R. Benkoczi, B. Bhattacharya, A. Tamir 陳冠伶‧王湘叡‧李佳霖‧張經略 Jun 12, 2007.
Static Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys. Operations are:  initialize/create  get (search)
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Space-time Tradeoffs for Longest-Common-Prefix Array Construction Simon J. Puglisi and Andrew Turpin
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 }
Introduction to Algorithms: Verification, Complexity, and Searching (2) Andy Wang Data Structures, Algorithms, and Generic Programming.
Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.
Compressing Bi-Level Images by Block Matching on a Tree Architecture Sergio De Agostino Computer Science Department Sapienza University of Rome ITALY.
Sorting – Lecture 3 More about Merge Sort, Quick Sort.
Ch3 /Lecture #4 Brute Force and Exhaustive Search 1.
Succinct Data Structures
Succinct Data Structures
Succinct Data Structures
Two equivalent problems
Ariel Rosenfeld Bar-Ilan Uni.
Orthogonal Range Searching and Kd-Trees
Minimum Spanning Tree Verification
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
Discrete Methods in Mathematical Informatics
Suffix trees.
Merge Sort Michael Morton.
String Data Structures and Algorithms
Approximating Points by A Piecewise Linear Function: I
Dynamic Programming II DP over Intervals
The LCA Problem Revisited
Bioinformatics Unit, ISTECH Inc.
Presentation transcript:

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

Lowest Common Ancestor After a O(n) time preprocessing, any LCA query can then be answered in O(1) time. Introduction

Outline Range Minimum Query (RMQ) Problem Reduce LCA to 1RMQ An Algorithm for 1RMQ

RMQ Problem Structure to Preprocess: An array A of numbers. Query: RMQ(i, j) returns the index of the smallest element in the subarray A[i...j] RMQ(4, 8) = 5.

1RMQ Problem A restricted case of RMQ such that all adjacent elements in the array A differ by +1 or -1. Example:

Level 1 Level 2 Level 3 Level 4 Reduce LCA to 1RMQ Compute the level array while visiting the tree in an Euler Tour

An O(nlogn) Preprocessing for RMQ An O(n 2 ) brute-force preprocessing: –precompute every query RMQ(i, j) An O(nlogn) preprocessing: –only precompute the queries whose length is a power of 2 (there are nlogn such queries at most)there are nlogn such queries at most –the preprocessing table can be computed in O(nlogn) by using dynamic programming. RMQ(i, j) = min(RMQ(i, (j-i+1)/2), RMQ((j-i+1)/2+1, j))

Constant Time RMQ ij RMQ(i, j) is the minima of the two blocks (one start at i and one end at j) covering the range [i,...,j].

An O(n) Preprocessing for 1RMQ Partition A into blocks of size ½logn Define an array A[1,..., n/½logn], where A[k] is the minimum element in the kth block of A. The RMQ preprocessing of A spends O(n/½logn x log(n/½logn)) = O(n) time and space. n ½logn

How to compute RMQ(i, j)? The answer is minimum of min(R1): The minimum from i forward to the end of its block. min(R2): The minimum of all the blocks in between is block and js block. min(R3): The minimum from the beginning of js block to j. The preprocessing of A can be used to compute min(R2). How to compute min(R1) and min(R3)? ½logn 123

An O(n) Preprocessing for 1RMQ Normalize each block of length ½logn to a binary string of length ½logn-1 Ex: => If two blocks normalize to the same binary string, the RMQ answers of these two blocks will be the same. There are only O( n) kinds of normalized blocks. There are only 2 (½logn)-1 = O( n) kinds of binary strings of length (½logn)-1. (Example)Example The total preprocessing time for all normalized block is O( nlognloglogn) = O(n).

There are logn such queries started at position i at most. i