Binary Search on a Tree Shay Mozes (Brown University)

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Bilinear Games: Polynomial Time Algorithms for Rank Based Subclasses Ruta Mehta Indian Institute of Technology, Bombay Joint work with Jugal Garg and Albert.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Dynamic All Pairs Shortest Paths Based on the following resources: Camil Demetrescu and Giuseppe F. Italiano (2004) A New Approach to Dynamic All Pairs.
Approximation Algorithms Chapter 5: k-center. Overview n Main issue: Parametric pruning –Technique for approximation algorithms n 2-approx. algorithm.
4/5/05Tucker, Sec Applied Combinatorics, 4rth Ed. Alan Tucker Section 4.3 Graph Models Prepared by Jo Ellis-Monaghan.
Chapter 3 The Greedy Method 3.
Jan. 2013Dr. Yangjun Chen ACS Outline Signature Files - Signature for attribute values - Signature for records - Searching a signature file Signature.
Branch and Bound Searching Strategies
16:36MCS - WG20041 On the Maximum Cardinality Search Lower Bound for Treewidth Hans Bodlaender Utrecht University Arie Koster ZIB Berlin.
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
Branch and Bound Similar to backtracking in generating a search tree and looking for one or more solutions Different in that the “objective” is constrained.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Minimal Spanning Trees. Spanning Tree Assume you have an undirected graph G = (V,E) Spanning tree of graph G is tree T = (V,E T E, R) –Tree has same set.
Jan 6-10th, 2007VLSI Design A Reduced Complexity Algorithm for Minimizing N-Detect Tests Kalyana R. Kantipudi Vishwani D. Agrawal Department of Electrical.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Computability and Complexity 24-1 Computability and Complexity Andrei Bulatov Approximation.
1 Branch and Bound Searching Strategies 2 Branch-and-bound strategy 2 mechanisms: A mechanism to generate branches A mechanism to generate a bound so.
Multiple Sequence alignment Chitta Baral Arizona State University.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding ILPs with Branch & Bound ILP References: ‘Integer Programming’
Decision Procedures An Algorithmic Point of View
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
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.
Simple and Improved Parameterized Algorithms for Multiterminal Cuts Mingyu Xiao The Chinese University of Hong Kong Hong Kong SAR, CHINA CSR 2008 Presentation,
Hungarian Algorithm Vida Movahedi Elderlab, York University June 2007.
APPROXIMATION ALGORITHMS VERTEX COVER – MAX CUT PROBLEMS
The Complexity of Optimization Problems. Summary -Complexity of algorithms and problems -Complexity classes: P and NP -Reducibility -Karp reducibility.
An Approximation Algorithm for Binary Searching in Trees Marco Molinaro Carnegie Mellon University joint work with Eduardo Laber (PUC-Rio)
Order Statistics. Order statistics Given an input of n values and an integer i, we wish to find the i’th largest value. There are i-1 elements smaller.
Binary Search From solving a problem to verifying an answer.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
8.3 Representing Relations Directed Graphs –Vertex –Arc (directed edge) –Initial vertex –Terminal vertex.
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
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Branch and Bound Searching Strategies
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
CSCI2950-C Genomes, Networks, and Cancer
Greedy algorithms: CSC317
Andreas Klappenecker [partially based on the slides of Prof. Welch]
CS1022 Computer Programming & Principles
AS Maths Decision Paper June 2011 Model Answers.
CSC 4170 Theory of Computation The class P Section 7.2.
Approximating the MST Weight in Sublinear Time
Decision trees Polynomial-Time
Paweł Gawrychowski, Nadav Krasnopolsky, Shay Mozes, Oren Weimann
CSC 4170 Theory of Computation The class P Section 7.2.
Maximum Matching in the Online Batch-Arrival Model
The Greedy Method and Text Compression
Advanced Algorithms Analysis and Design
Minimal Spanning Trees
Algorithm design and Analysis
Elementary Graph Algorithms
Theory of Computability
CSE 373: Data Structures and Algorithms
EE5900 Advanced Embedded System For Smart Infrastructure
The Theory of NP-Completeness
Major Design Strategies
The Selection Problem.
CSE 373: Data Structures and Algorithms
Switching Lemmas and Proof Complexity
Bin Packing Michael T. Goodrich Some slides adapted from slides from
Theory of Computability
Major Design Strategies
Presentation transcript:

Binary Search on a Tree Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Locating differences – Binary Search on a Tree ? ? Directories checksums = 4

Locating differences – Binary Search on a Tree ? ? Directories checksums = 5

Search Startegy search strategy = decision tree Optimal strategy = shallowest decision tree a (a,c)? (a,b)? (c,e)? a c (a,d)? b d (c,f)? (e,g)? e f g b d c e f Binary search – tree is a line. Decision tree – complete binary tree g

Searching in trees and posets Related Work Tree edge ranking Searching in trees and posets IRV [Disc. Appl. Math. 1991]: 2-approx. in O(nlogn) TGS [Algorithmica 1995]: O(n3logn) LY [SODA 1998]: O(n) BFN [SODA 1997]: O(n4log3n) LN [ENDM 2001]: 2-approx. in O(nlogn) OP [FOCS 2006]: O(n3) This paper: O(n) Applications: Ours: filesystem sync, bug detection Ranking: VLSI design, matrix factorization BFN – Ben Asher Farchi Newman LN – Laber Nogueira OP = Onak Parys IRV – Iyer, Ratliff, Vijayan TGS – de la Torre, Greenlaw, Schaffer LY – Lam, Yue

Strategy Function f : E → {1,2,3,…} If f(e1 ) = f(e2 ), then on the path from e1 to e2 there is e3 with f(e3 ) > f(e1 ) = f(e2 ) strategy function bounded by k decision tree of height k a (a,c)? (a,b)? (c,e)? a c (a,d)? b d (c,f)? (e,g)? e f g 3 2 1 Intuition: f(e) = k, at most k more queries to go. b d c e f g

Solution Approach Given tree Find strategy function with the least maximum Convert into a decision tree c a d f e g b (a,c)? (a,b)? (c,e)? a c (a,d)? b d (c,f)? (e,g)? e f g 3 2 1

Visibility e is visible from vertex v if on path from v to e there is no value greater than e Lexicographic order on visibility sequences e.g.: (3,2,1) > (3,1) 3,1 a 1 3 3,2,1 d c 2 1 e f 1 g

Bottom-Up Approach Given visibility sequences at children of v Extend to minimal visibility sequence at v Theorem [OP, de la Torre et al.]: Minimal extensions accumulate to an optimal solution Given strategy functions at children of v v 2 3 3 2 c d f e g 2 1 2 1 1

Valid Extension . . . An extension assigns all f(ei)’s v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 4 1 1 . . .

Valid Extension . . . An extension assigns all f(ei)’s f(ei)= f(ej) v 3 3 f(ek)? s1 s2 sk 4 1 4 1 1 . . .

Valid Extension . . . An extension assigns all f(ei)’s f(ei)= f(ej) f(ei) is not in si v 4 f(e2)? f(ek)? s1 s2 sk 4 1 4 1 1 . . .

Valid Extension . . . An extension assigns all f(ei)’s f(ei)= f(ej) f(ei) is not in si f(ei) is in sj f(ej) > f(ei) v 3 f(e2)? 4 s1 s2 sk 4 1 4 1 1 . . .

Valid Extension . . . An extension assigns all f(ei)’s f(ei)= f(ej) f(ei) is not in si f(ei) is in sj f(ej) > f(ei) u is in si and sj max{f(ei), f(ei)} > u v 2 3 f(ek)? s1 s2 sk 4 1 4 1 1 . . .

Algorithm Outline . . . v f(e1)? f(e2)? f(ek)? s1 s2 sk free values 1 4 1 1 1 . . . free values 1 2 3 4 5 6

Algorithm Outline . . . set u = max{si} u v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . u is most problematic u free values 1 2 3 4 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned u v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . u free values 1 2 3 4 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . - u is not problematic cause appears only once, but is not free to use again - Next largest u that actually appears in some s_i u free values 1 2 3 4 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . u free values 1 2 3 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . u free values 1 2 3 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . w is smallest value that can resolve u w u w free values 1 2 3 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . Its best to assign w to the visibility sequence s.t w makes many values in it disappear – -NOT NECCESARILY ONE OF THE EDGES THAT u APPEARS IN w u w free values 1 2 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free v f(e1)? f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . w u w free values 1 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . w u w free values 1 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 1 . . . No such values since no integer between 1 and 2 w u w free values 1 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 . . . w u w free values 1 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 . . . u free values 1 3 5 6

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 1 3 5 6 Sj

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 f(e2)? f(ek)? s1 s2 sk 4 1 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 1 5 6 Sj 31

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 3 f(ek)? s1 s2 sk 4 1 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 1 5 6 Sj 32

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 3 f(ek)? s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 1 5 6 Sj 33

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj v 2 3 f(ek)? s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u free values 1 5 6 34

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 2 3 f(ek)? s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u free values 5 6 35

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 2 3 f(ek)? w s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 5 6 Sj 36

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 2 3 f(ek)? w s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 6 Sj 37

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 5 3 f(ek)? w s1 s2 sk 4 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 2 6 Sj 38

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 5 3 f(ek)? w s1 s2 sk 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u w free values 2 4 6 Sj 39

Algorithm Outline . . . set u = max{si} while not all edges assigned u if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 5 3 f(ek)? s1 s2 sk 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! u free values 2 4 6 40

Algorithm Outline . . . set u = max{si} while not all edges assigned w if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 5 3 f(ek)? s1 s2 sk 1 . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! w u w free values 2 4 6 Sj 41

That’s it! Algorithm Outline . . . set u = max{si} while not all edges assigned if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v 5 3 2 s1 s2 sk . . . Here you can see that the maximal sequence w.r.t w is one that does not contain u ! w u w free values 4 6 Sj 42

That’s it! Algorithm Outline set u = max{si} while not all edges assigned if u appears once mark u as not free, move to next largest u otherwise: w = smallest free value > u Sj = any maximal sequence w.r.t w mark w as not free set current f(ej) = w (free previous value) mark all Sj values between u and w as free remove all values < w from Sj and u = 0 v s1 s1 5 3 2

Running Time v s1 s2 sk 4 1 1 1 . . .

Running Time Easy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total v s1 s2 sk 4 1 1 1 But we can actually do it in |s_1|+…+|s_k| yielding n^2 time complexity ! . . . 45

Running Time Easy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total But, |S1| + |S2| +…+ |Sk| is not a lower bound! v s1 s2 sk 4 1 1 1 But we can actually do it in |s_1|+…+|s_k| yielding n^2 time complexity ! . . . 46

Running Time Easy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total But, |S1| + |S2| +…+ |Sk| is not a lower bound! in many cases, the largest values of the largest visibility sequence are unchanged at v itself v s1 s2 sk 4 1 1 1 But we can actually do it in |s_1|+…+|s_k| yielding n^2 time complexity ! . . . 47

Σ Linear Running Time . . . q(v) = |S2| +…+ |Sk| k(v) = #v’s children t(v) = largest value that appears in Sv but not in S1 Theorem: an extension can be computed in time O( k(v)+q(v)+t(v) ) Theorem: k(v)+q(v)+t(v) = O(n) Differs from [LY98]: different data structures No bit tricks O(n) decision tree construction v Σ v s1 s2 sk 4 1 1 1 Different than Lam and Yue’s solution. Many details omitted . . .

From Strategy Function to Decision Tree in O(n) Time

From Strategy Function to Decision Tree in O(n) Time (a,c)? 2 1 a c 3 b d c (a,b)? (c,e)? 2 1 a b c e e f 1 (a,d)? b (c,f)? (e,g)? a d c f e g g a d c f e g

From Strategy Function to Decision Tree in O(n) Time (a,c)? For all edges e let s = visibility sequence at bottom(e) if s contains no values smaller than f(e) set bottom(e) as the solution when the query on e returns bottom(e) else, let v1 <...< vk < f(e) in s, let ei be the edge vi is assigned to set ek as the solution when the query on e returns bottom(e) for every 1≤ i <k set ei as the solution when the query on ei+1 returns top(ei+1) set top(e1) as the solution when the query on e1 returns top(e1) 2 1 a c 3 b d c (a,b)? (c,e)? 2 1 a b c e e f 1 (a,d)? b (c,f)? (e,g)? a d c f e g g a d c f e g

Thank You!