Lowest common ancestors. Write an Euler tour of the tree 3 4 5 1 6 7 2 4171356533123 1 2 3 4 6 9 10 85 7 1112 0 LCA(1,5) = 3 Shallowest node.

Slides:



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

CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Other Dynamic Programming Problems
Succinct Data Structures for Permutations, Functions and Suffix Arrays
1 Appendix B: Solving TSP by Dynamic Programming Course: Algorithm Design and Analysis.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
Advanced Databases: Lecture 2 Query Optimization (I) 1 Query Optimization (introduction to query processing) Advanced Databases By Dr. Akhtar Ali.
Constant-Time LCA Retrieval
Suffix Sorting & Related Algoritmics Martin Farach-Colton Rutgers University USA.
Suffix Sorting & Related Algoritmics Martin Farach-Colton Rutgers University USA.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Advanced Topics in Algorithms and Data Structures Lecture pg 1 Recursion.
Dynamic Programming (II)
Nonholonomic Multibody Mobile Robots: Controllability and Motion Planning in the Presence of Obstacles (1991) Jerome Barraquand Jean-Claude Latombe.
1 Nearest Commen Ancestors (NCA) Discrete Range Maximum Cartesian Tree [Vuillemin 1980] i j max(i, j) i.
MIN-COST ABORESCENCES YQ Lu. Aborescence Definition: Given a directed graph G=(V,E) and a root r, an aborescence rooted at r is a subgraph T that each.
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):
Linear Programming Special Cases Alternate Optimal Solutions No Feasible Solution Unbounded Solutions.
Advanced Topics in Algorithms and Data Structures 1 Lecture 4 : Accelerated Cascading and Parallel List Ranking We will first discuss a technique called.
Accelerated Cascading Advanced Algorithms & Data Structures Lecture Theme 16 Prof. Dr. Th. Ottmann Summer Semester 2006.
UNC Chapel Hill Lin/Manocha/Foskey Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject.
Improvements on the Range-Minimum-Query- Problem
Algorithms All pairs shortest path
The Design and Analysis of Algorithms
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.
Algorithm Engineering, September 2013Data Structures, February-March 2010Data Structures, February-March 2006 Cache-Oblivious and Cache-Aware Algorithms,
The Encoding Complexity of Two Dimensional Range Minimum Data Structures MADALGO, October 2, 2013 (Work presented at ESA 2013) 1234  n
The Encoding Complexity of Two Dimensional Range Minimum Data Structures European Symposium on Algorithms, Inria, Sophia Antipolis, France, September 3,
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Integer programming Branch & bound algorithm ( B&B )
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
The LCA Problem Revisited Michael A.Bender & Martin Farach-Colton Presented by: Dvir Halevi.
The LCA Problem Revisited
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
DP (not Daniel Park's dance party). Dynamic programming Can speed up many problems. Basically, it's like magic. :D Overlapping subproblems o Number of.
Gary Sham HKOI 2010 Greedy, Divide and Conquer. Greedy Algorithm Solve the problem by the “BEST” choice. To find the global optimal through local optimal.
Pawe ł Gawrychowski* and Pat Nicholson** *University of Warsaw **Max-Planck-Institut für Informatik.
Public Key Systems 1 Merkle-Hellman Knapsack Public Key Systems 2 Merkle-Hellman Knapsack  One of first public key systems  Based on NP-complete problem.
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 }
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Dynamic Programming. Many problem can be solved by D&C – (in fact, D&C is a very powerful approach if you generalize it since MOST problems can be solved.
1 Nearest Common Ancestors (NCA) Discrete Range Maximum Cartesian Tree [Vuillemin 1980] i j max(i, j) i.
Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject to some constraints. (There may.
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 18.
TU/e Algorithms (2IL15) – Lecture 3 1 DYNAMIC PROGRAMMING
LOWEST COMMON ANCESTOR IN TREE CPSC 490 – FEBRUARY 24 TH – MICHAEL HILAND.
Example 2 You are traveling by a canoe down a river and there are n trading posts along the way. Before starting your journey, you are given for each 1
On the R ange M aximum-Sum S egment Q uery Problem Kuan-Yu Chen and Kun-Mao Chao Department of Computer Science and Information Engineering, National Taiwan.
Succinct Data Structures
Succinct Data Structures
Two equivalent problems
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
Chapter 8 Dynamic Programming
Ariel Rosenfeld Bar-Ilan Uni.
Orthogonal Range Searching and Kd-Trees
Fast Trie Data Structures
Minimum Spanning Tree Verification
Chapter 6. Large Scale Optimization
Lecture 19-Problem Solving 4 Incremental Method
Suffix trees.
Numerical Algorithms Quiz questions
Approximating Points by A Piecewise Linear Function: I
On the Range Maximum-Sum Segment Query Problem
The LCA Problem Revisited
Discrete Range Maximum
Chapter 6. Large Scale Optimization
Presentation transcript:

Lowest common ancestors

Write an Euler tour of the tree LCA(1,5) = 3 Shallowest node

minimum

Range minimum minimum Preprocess an array, such that given i,j you can find the minimum in [i,j] fast Reduction takes linear time

Trivial algorithms for RMQ

Less trivial algorithms to RMQ Try to use O(nlog(n)) space to do a query in O(1) time

... …... B[0]B[2n/logn]B[i] …... A’[0]A’[2n/logn]A’[i] Rememeber the min in each block (A’) and its position (B) Optimal solution

n=16 A[] : … = A’[] : … B[] : … Example

Preprocess A’ for RMQ using the O(nlog(n)) space algorithm. Since the size of A’ is this would take Space, preprocessing time

i and j might be in the same block, we need some mechanism to answer inside blocks i < j on different blocks, answer the query as follows: 1.Compute minima from i to end of its block. 2.Compute minima of all blocks in between i’s and j’s blocks. 3.Compute minima from the beginning of j’s block to j. Return the index of the minimum of these 3 values. How do we answer queries ?

So what do we do inside blocks?

We need to solve a special case of RMQ restriction

Each subproblem can be described by the first entry and a vector of ±1 Two subproblems with the same vector of ±1 are equivalent

The bottom line There aren’t too many different subproblems, only For each such subproblem prepare all answers in advance 

Pick a subproblem: Find the solution using i,j:

... …... B[0]B[2n/logn]B[i] …... A’[0]A’[2n/logn]A’[i] Summary Each block know its subproblem (A’’) …... A’’[0]A’’[2n/logn]A’’[i]