520 likes | 642 Views
Binary Search on a Tree. Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT). Locating differences – Binary Search on a Tree. ?. ?. =. 4. Locating differences – Binary Search on a Tree. ?. ?. =. 5. (a,c)?. c. a. (a,b)?. (c,e)?. e. c. a. b. b. (a,d)?.
E N D
Binary Searchon a Tree Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)
(a,c)? c a (a,b)? (c,e)? e c a b b (a,d)? (c,f)? (e,g)? a e g d c f a c d f e g Search Startegy • search strategy = decision tree • Optimal strategy = shallowest decision tree a b d c e f g
Related Work Tree edge ranking • BFN [SODA 1997]:O(n4log3n) • LN [ENDM 2001]:2-approx. in O(nlogn) • OP [FOCS 2006]:O(n3) • This paper: O(n) 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)
Strategy Function strategy function bounded by k decision tree of height k (a,c)? c a (a,b)? (c,e)? 1 e c a 2 b 3 b (a,d)? (c,f)? (e,g)? a e g d c f 1 2 a c d f e g 1 • 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 ) a b d c e f g
(a,c)? c a (a,b)? (c,e)? 1 e c a 2 b a 3 b (a,d)? (c,f)? (e,g)? a e g d c f b d 1 2 c a c d f e g 1 e f g Solution Approach • Given tree • Find strategy function with the least maximum • Convert into a decision tree
3,1 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 sequencese.g.: (3,2,1) > (3,1) a 1 3 d c 1 2 e f 1 g
3 2 c d 1 2 1 e f 1 f g Bottom-Up Approach • Given strategy functions at children of v • 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 v
Valid Extension • An extension assigns all f(ei)’s v f(e1)? f(e2)? f(ek)? s1 s2 sk . . .
Valid Extension • An extension assigns all f(ei)’s • f(ei)= f(ej) v 3 3 f(ek)? s1 s2 sk . . .
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 . . .
Valid Extension • An extension assigns all f(ei)’s • f(ei)= f(ej) • f(ei) is not in si • f(ei) is in sjf(ej) > f(ei) v 3 4 f(e2)? s1 s2 sk . . .
Valid Extension • An extension assigns all f(ei)’s • f(ei)= f(ej) • f(ei) is not in si • f(ei) is in sjf(ej) > f(ei) • u is in siand sjmax{f(ei), f(ei)} > u v 2 3 f(ek)? s1 s2 sk . . .
Algorithm Outline v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . free values
Algorithm Outline • set u = max{si} v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . u free values
Algorithm Outline • set u = max{si} • while not all edges assigned v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . u free values
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 v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . u free values
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 v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . u free values
Algorithm Outline v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . u free values • set u = max{si} • while not all edges assigned • if u appears once mark u as not free, move to next largest u • otherwise:
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 v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . w u w free values
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= anymaximal sequence w.r.tw v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . w u w free values Sj
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= anymaximal sequence w.r.tw • mark w as not free v f(e1)? f(e2)? f(ek)? s1 s2 sk . . . w u w free values Sj
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= anymaximal sequence w.r.tw • mark w as not free • set currentf(ej) = w v 2 f(e2)? f(ek)? s1 s2 sk . . . w u w free values Sj
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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free v 2 f(e2)? f(ek)? s1 s2 sk . . . w u w free values Sj
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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj v 2 f(e2)? f(ek)? s1 s2 sk . . . w u w free values Sj
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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj v 2 f(e2)? f(ek)? s1 s2 sk . . . u free values
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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj v 2 f(e2)? f(ek)? s1 s2 sk . . . u w free values Sj
Algorithm Outline v 2 f(e2)? f(ek)? s1 s2 sk . . . u w free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj Sj
Algorithm Outline v 2 3 f(ek)? s1 s2 sk . . . u w free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj Sj
Algorithm Outline v 2 3 f(ek)? s1 s2 sk . . . u w free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj Sj
Algorithm Outline v 2 3 f(ek)? s1 s2 sk . . . u free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj
Algorithm Outline and u= 0 v 2 3 f(ek)? s1 s2 sk . . . u free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj
Algorithm Outline and u= 0 v 2 3 f(ek)? w s1 s2 sk . . . w u free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj Sj
Algorithm Outline and u= 0 v 2 3 f(ek)? w s1 s2 sk . . . w u free values • 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= anymaximal sequence w.r.tw • mark w as not free • set current f(ej) = w • mark allSj values between u and w as free • remove all values < w fromSj Sj
Algorithm Outline and u= 0 v 5 3 f(ek)? w s1 s2 sk . . . w u free values • 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 = anymaximal 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 fromSj Sj
Algorithm Outline and u= 0 v 5 3 f(ek)? w s1 s2 sk . . . w u free values • 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 = anymaximal 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 fromSj Sj
Algorithm Outline and u= 0 v 5 3 f(ek)? s1 s2 sk . . . u free values • 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 = anymaximal 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 fromSj
Algorithm Outline and u= 0 v 5 3 f(ek)? s1 s2 sk . . . w w u free values • 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 = anymaximal 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 fromSj Sj
Algorithm Outline That’s it! and u= 0 v 5 3 2 s1 s2 sk . . . w w u free values • 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 = anymaximal 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 fromSj Sj
Algorithm Outline That’s it! • 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 = anymaximal 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 fromSj and u= 0 v s1 s1
Running Time v s1 s2 sk . . .
Running Time v s1 s2 sk . . . Easy in O(|S1| + |S2| +…+ |Sk|) per vertexO(n2) total
Running Time v s1 s2 sk . . . Easy in O(|S1| + |S2| +…+ |Sk|) per vertexO(n2) total But, |S1| + |S2| +…+ |Sk| is not a lower bound!
Running Time • in many cases, the largest values of the largest visibility sequence are unchanged at v itself v s1 s2 sk . . . Easy in O(|S1| + |S2| +…+ |Sk|) per vertexO(n2) total But, |S1| + |S2| +…+ |Sk| is not a lower bound!
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 . . .
From Strategy Function to Decision Tree in O(n) Time (a,c)? a 1 2 c a 3 b d (a,b)? (c,e)? c 2 1 c e b a e f b 1 (a,d)? (c,f)? (e,g)? a g c d e f g a c d f e g