19
1 HEINZ NIXDORF INSTITUTE University of Paderborn Algorithms and Complexity Christian Schindelhauer Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture Christian Schindelhauer [email protected]

Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Embed Size (px)

DESCRIPTION

Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture. Christian Schindelhauer [email protected]. Spatial Searching. Prolog: Searching with some help Searching with total Uncertainty Nearsighted Search The Cow Path Problem The Concept of Competitive Analysis - PowerPoint PPT Presentation

Citation preview

Page 1: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

1

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Search AlgorithmsWinter Semester 2004/2005

10 Jan 200511th Lecture

Christian [email protected]

Page 2: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 2

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Spatial Searching

Prolog: Searching with some help

Searching with total Uncertainty Nearsighted Search

– The Cow Path Problem– The Concept of Competitive Analysis– Deterministic Solution– Finding a Shoreline– Searching without help– Probabilistic Solution – The Wall Problem

Farsighted Search– The Watchman Problem– How to Learn your Environment

Page 3: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 3

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Searching with some Help

From “Searching with Uncertainty”, Kranakis, Krizanc, SIROCCO, 1999, 194-203

Problem:–In Manhattan you are looking for a restaurant–You ask a policeman at every crossing for directions–This policeman stays at his crossing–There is a constant error probability p<1/2 that this information is wrong

Task:–Find the restaurant as fast as possible–with respect to the start distance d

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.

???

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.

???

Page 4: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 4

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Main Problem

If you rely all policemen there is a constant probability that you get stuck

If you ignore the advice of the policemen you need much more time

– Then you can use a spiral approach taking O(d2) steps

target

start

Page 5: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 5

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Solution for the 1-Dimensional Case

Consider a ring of length nSearch-Ring(k)1. dir direction at start position2. for i1 to n or target is reached do3. move in direction dir4. od5. if the majority of the policeman

met so far agree then6. continue in direction dir until

target is found7. else8. reverse direction dir and

continue until target is found

9. fi

Observation: The probability that Search-Ring continues in the correct direction after k steps is

Page 6: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 6

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The probability to make a wrong decision is given by

Observe

To describe Xm m/2 we set

This leads to

Let m = c log n and c’=min(,2) then the error probability is

Analysis of the Ring Case

TheoremSearch-Ring(k) for k=(log n) solves the search problem within d+O(log n) steps with high probability, i.e. 1-n-O(1).

Proof Consider Bernoulli experiment of Xi of

choosing direction with probability p for outcome 1 and probability 1-p for outcome 0.

Chernoff bound:– For independent Bernoulli variable Xi

and with

Page 7: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 7

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The 2-Dimensional Case

Assumptions– Torus street map

– Policemen point to east/west bound direction before showing to north/south bound direction

• (if their advice is correct).

Page 8: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 8

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Block-Wise Approach

Consider Blocks of size (log n) x (log n) Properties (with high probability)

– West/east bound directions can be decided correctly with high probability

– If the target is north/south bound from a block this can be decided correctly by scanning all the columns of a block

Kranakis-Krizanc-Search1. Apply horizontal Search-Ring(c log n) to find the

west/east bound direction2. Follow this direction until a majority of policemen

in a block advises to go into the opposite direction3. Find the correct vertical column in the current

block and the block visited before4. Move along the vertical direction until the target is

found or the majority of policemen points backwards

5. If the target has not been found by now, perform a spiral search

Page 9: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 9

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Performance of Kranakis-Krizanc-Search

TheoremWith high probability the Kranakis-Krizanc-Search finds the target in d + O(log2 n) steps.

Proof:Follows by applying Chernoff bounds

Discusssion:

Prefering horizontal directions over vertical ones is an (unnecessary) simplification

The block-wise approach can solve this problem as well, since either the horizontal or the vertical direction can be detected by a walk through a block

– This results in an algorithm with same performance (exercise!!)Policemen help a lot

Page 10: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 10

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Cow-Path Problem

Given–A near-sighted cow–A fence with a gate–The cow does not know the direction

Task–Find the exit as fast as possible

???

Page 11: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 11

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Competitive Analysis

How to evaluate the online solutionClassical approach:

– Worst-case time• This is always n for a fence of length n

– Average case• This is not better

Competitive Analysis– Compare the cost of the solution of an

instance x• CostAlg(x)

– to the best possible offline solution (unknown to the cow)

• Costoffline(x)Minimize the competitive ratio

=

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Page 12: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 12

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Rental Ski Problem

Problem–Buying a pair of skis costs 100 Euro–Renting a pair of skis one day costs 10 Euro

How many days do we have snow?Shall we buy or rent?

1st Solution: Buy on the first snow day

Buy one the first day of snow–CostBuy(1) = 100

Worst case = 1 day of snow –Costoffline(1) = 10 (1 day renting)

2nd Solution: Always rentRent every day

–For x snow days–CostBuy(x) = 10 x

Worst case = always snow–best strategy: buy on the first day–Costoffline(1) = 100

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Page 13: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 13

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

A Better Solution for the Rental Ski Problem

Rent&Buy1. Rent for 10 days2. Then Buy on the 11th day

Cost for x<11 days of snow:– CostRent&Buy (x) = 10x

Cost for x>10 days of snow:– CostRent&Buy (x) = 200

Best strategy for x<11 days of snow:– Rent for x days– Costoffline (x) = 10x

Best strategy for x>10 days of snow:– Buy on the first day– Costoffline (x) = 100

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Page 14: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 14

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Solution of the Cow Fence Problem

Deterministic Cow-Path1. dir left2. for i 0 to log n do3. go 2i steps to direction dir4. go 2i steps back to the origin5. revert direction dir6. od

Theorem [Baeza-Yates, Culberson, Rawlins, 1993]

The deterministic Cow-Path algorithm has a competitive ratio of 9.This competitive ratio is optimal.

Page 15: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 15

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Exit

Performance of the Cow-Path Algorithm

Performance of the best (offline) strategy: d

– where d is the shortest way to the exit Worst case of the Cow-Path Algorithm

– d = 2x+1– Let d’=d-1

Number of steps before finding the exit:1+1+2+2+4+4+...+d’/2+d’/2+d’+d’+2d’+2d’+d’+1 = 9 d’-1 = 9 d - 10

d’2d’d’2d’d’+1

d’/2d’/4 ...

Page 16: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 16

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Shoreline Problem

Problem description A boat is lost in a half ocean with a linear

shoreline No compass on board No sight because of dense fog The distance to the shoreline is unknown

Task Find the coast as fast as possible

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.Zur Anzeige wird der QuickTime™

Dekompressor „TIFF (Unkomprimiert)“ benötigt.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“

benötigt.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (Unkomprimiert)“ benötigt.?

Page 17: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 17

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

The Spiral Solution for the Shoreline ProblemBaeza-Yates, Culberson, Rawlins, 1993

Solution: Use logarithmic spiral obeying

– where r is the polar radius from the starting point

– and is the polar angle

Numerical optimization leads to a competitive optimal ratio for k=1.250...

The shoreline problem can be solved using the logarithmic spiral method with competitive ratio 13.81...

1

k2

Page 18: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

Search Algorithms, WS 2004/05 18

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Searching for a point in a Grid

Problem:– Find a spot in a grid without knowing

the coordinates– (finding the restaurant in New York

without policemen) Solution:

– Use a spiral covering all points in Hamming distance 1,2,3,4,...

Theorem [Baeza-Yates, Culberson, Rawlins, 1993]

– Using the spiral method this problem can be solved with competitive ratio 2d, where d is the Hamming distance between start and target.

– This competitive ratio is optimal.

Zur Anzeige wird der QuickTime™ Dekompressor „TIFF (LZW)“

benötigt.

Page 19: Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture

19

HEINZ NIXDORF INSTITUTEUniversity of Paderborn

Algorithms and ComplexityChristian Schindelhauer

Thanks for your attentionEnd of 11th lecture

Next lecture: Mo 17 Jan 2005, 11.15 am, FU 116Next exercise class: Mo 10 Jan 2005, 1.15 pm, F0.530 or We 12 Jan 2005, 1.00 pm, E2.316