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

Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Jan 19, 2016

Download

Documents

Gabriel Francis

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)?. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Shay Mozes (Brown University)

Krzysztof Onak (MIT)

Oren Weimann (MIT)

Binary Searchon a Tree

Page 2: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)
Page 3: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)
Page 4: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

?

4

Locating differences – Binary Search on a Tree

?

=

Page 5: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

5

? ?

=

Locating differences – Binary Search on a Tree

Page 6: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

• search strategy = decision tree

• Optimal strategy = shallowest decision tree

c

a

d

fe

g

b

(a,c)?

(a,b)? (c,e)?

a c

(a,d)?

a b

b

dd

a

a

(c,f)? (e,g)?

c e

ff

cc

g

ge

e

Search Startegy

Page 7: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Related Work

• BFN [SODA 1997]:O(n4log3n)

• LN [ENDM 2001]:2-approx. in O(nlogn)

• OP [FOCS 2006]:O(n3)

• This paper: O(n)

• IRV [Disc. Appl. Math. 1991]: 2-approx. in O(nlogn)

• TGS [Algorithmica 1995]: O(n3logn)

• LY [SODA 1998]:O(n)

Searching in trees and posets

Tree edge ranking

Page 8: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

• 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 )

c

a

d

fe

g

b

(a,c)?

(a,b)? (c,e)?

a c

(a,d)?

a b

b

dd

a

a

(c,f)? (e,g)?

c e

ff

cc

g

ge

e

Strategy Function

32

2

1

1

1

strategy function bounded by k

decision tree of height k

Page 9: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

• Given tree

• Find strategy function with the least maximum

• Convert into a decision tree

c

a

d

fe

g

b

(a,c)?

(a,b)? (c,e)?

a c

(a,d)?

a b

b

dd

a

a

(c,f)? (e,g)?

c e

ff

cc

g

ge

e

Solution Approach

32

2

1

1

1

Page 10: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

• 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)

c

a

d

fe

g

Visibility

3

2

1

1

1

3,1

3,2,1

Page 11: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

• 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

Bottom-Up Approach

c d

fe

g

2 1

1 f

1

• Given strategy functions at children of v

1

2

1

23

3

2

Page 12: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Valid Extension

An extension assigns all f(ei)’s

s1 s2 sk

. . .

v

4

1

0

4

1

0

1

0

f(e1)? f(ek)?f(e2)?

Page 13: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Valid Extension

An extension assigns all f(ei)’s f(ei)= f(ej)

s1 s2 sk

. . .

v

4

1

0

4

1

0

1

0

3 f(ek)?3

Page 14: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Valid Extension

An extension assigns all f(ei)’s f(ei)= f(ej)

f(ei) is not in si

s1 s2 sk

. . .

v

4

1

0

4

1

0

1

0

4 f(ek)?f(e2)?

Page 15: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

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)

s1 s2 sk

. . .

v

4

1

0

4

1

0

1

0

3 4f(e2)?

Page 16: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

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

s1 s2 sk

. . .

v

4

1

0

4

1

0

1

0

2 3

f(ek)?

Page 17: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 2 3 4 5 6free values

Page 18: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

s1 s2

. . .

v

4

1

0

1

0

1

0

f(e1)? f(e2)?

0 1 2 3 4 5 6free values

u

sk

f(ek)?

Page 19: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assigned

s1 s2

. . .

v

4

1

0

1

0

1

0

f(e1)? f(e2)?

0 1 2 3 4 5 6free values

u

sk

f(ek)?

Page 20: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif u appears once mark u as not free, move to next largest u

s1 s2

. . .

v

4

1

0

1

0

1

0

f(e1)? f(e2)?

0 1 2 3 4 5 6free values

u

sk

f(ek)?

Page 21: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif u appears once mark u as not free, move to next largest u

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 2 3 5 6free values

u

Page 22: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif u appears once mark u as not free, move to next largest u

otherwise:

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 2 3 5 6free values

u

Page 23: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif u appears once mark u as not free, move to next largest u

otherwise: w = smallest free value > u

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 2 3 5 6free values

u ww

Page 24: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 2 3 5 6free values

u ww

Sj

Page 25: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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 s1 s2 sk

. . .

v

4

1

0

1

0

1

0

f(e1)? f(ek)?f(e2)?

0 1 3 5 6free values

u ww

Sj

Page 26: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

2 f(ek)?f(e2)?

0 1 3 5 6free values

u ww

Sj

Page 27: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

2 f(ek)?f(e2)?

0 1 3 5 6free values

u ww

Sj

Page 28: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

2 f(ek)?f(e2)?

0 1 3 5 6free values

u ww

Sj

Page 29: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

2 f(ek)?f(e2)?

0 1 3 5 6free values

u

Page 30: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

2 f(ek)?f(e2)?

0 1 3 5 6free values

u w

Sj

Page 31: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

2 f(ek)?f(e2)?

0 1 5 6free values

u w

Sj

Page 32: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

1

0

2 f(ek)? 3

0 1 5 6free values

u w

Sj

Page 33: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

2 f(ek)? 3

0 1 5 6free values

u w

Sj

Page 34: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

2 f(ek)? 3

0 1 5 6free values

u

Page 35: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

2 f(ek)? 3

0 5 6free values

u

and u = 0

Page 36: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

2 f(ek)? 3

0 5 6free values

u

w

w

and u = 0

Sj

Page 37: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

2 f(ek)? 3

0 6free values

u

w

w

and u = 0

Sj

Page 38: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

4

1

0

5 f(ek)? 3

0 2 6free values

u

w

w

and u = 0

Sj

Page 39: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

1

0

5 f(ek)? 3

0 2 4 6free values

u

w

w

and u = 0

Sj

Page 40: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

1

0

5 f(ek)? 3

0 2 4 6free values

u

and u = 0

Page 41: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

1

0

5 f(ek)? 3

0 2 4 6free values

u w

and u = 0

w

Sj

Page 42: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1 s2 sk

. . .

v

5 2 3

4 6free values

u w

and u = 0

w

Sj

That’s it!

Page 43: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Algorithm Outline

set u = max{si}

while not all edges assignedif 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

s1

vand u = 0

s15

3

2

That’s it!

Page 44: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Running Time

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

Page 45: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Running TimeEasy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

Page 46: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Running TimeEasy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total

But, |S1| + |S2| +…+ |Sk| is not a lower bound!

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

Page 47: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Running TimeEasy in O(|S1| + |S2| +…+ |Sk|) per vertex O(n2) total

But, |S1| + |S2| +…+ |Sk| is not a lower bound!

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

in many cases, the largest values of the largest visibility sequence are unchanged at v itself

Page 48: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Linear Running Time

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

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

Page 49: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

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

Page 50: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

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

c

a3

d

fe

g

2 1

2 1

1

(a,c)?

(a,b)? (c,e)?

a c

(a,d)?

a b

b

bdd

aa

(c,f)? (e,g)?

c e

ff

cc

g

ge

e

Page 51: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

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

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 toset 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)

c

a3

d

fe

g

2 1

2 1

1

(a,c)?

(a,b)? (c,e)?

a c

(a,d)?

a b

b

bdd

aa

(c,f)? (e,g)?

c e

ff

cc

g

ge

e

Page 52: Shay Mozes (Brown University) Krzysztof Onak (MIT) Oren Weimann (MIT)

Thank You!