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

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

feis fei

Welcome message from author
Transcript

Shay Mozes (Brown University)

Krzysztof Onak (MIT)

Oren Weimann (MIT)

Binary Searchon a Tree

?

4

Locating differences – Binary Search on a Tree

?

=

5

? ?

=

Locating differences – Binary Search on a Tree

• 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

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

• 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

• 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

• 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

• 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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!

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!

Running Time

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

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

s1 s2 sk

. . .

v

4

1

0

1

0

1

0

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

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

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

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

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

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

Thank You!