190 likes | 317 Views
Search Algorithms Winter Semester 2004/2005 10 Jan 2005 11th Lecture. Christian Schindelhauer schindel@upb.de. Spatial Searching. Prolog: Searching with some help Searching with total Uncertainty Nearsighted Search The Cow Path Problem The Concept of Competitive Analysis
E N D
Search AlgorithmsWinter Semester 2004/200510 Jan 200511th Lecture Christian Schindelhauer schindel@upb.de
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
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 ??? ???
The Main Problem start • 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
The Solution for the 1-Dimensional Case • Consider a ring of length n Search-Ring(k) • dir direction at start position • for i1 to n or target is reached do • move in direction dir • od • if the majority of the policeman met so far agree then • continue in direction dir until target is found • else • reverse direction dir and continue until target is found • fi Observation: The probability that Search-Ring continues in the correct direction after k steps is
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 Theorem Search-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
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).
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-Search • Apply horizontal Search-Ring(c log n) to find the west/east bound direction • Follow this direction until a majority of policemen in a block advises to go into the opposite direction • Find the correct vertical column in the current block and the block visited before • Move along the vertical direction until the target is found or the majority of policemen points backwards • If the target has not been found by now, perform a spiral search
Performance of Kranakis-Krizanc-Search Theorem With 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
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 ???
Competitive Analysis • How to evaluate the online solution • Classical 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 =
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 rent • Rent every day • For x snow days • CostBuy(x) = 10 x • Worst case = always snow • best strategy: buy on the first day • Costoffline(1) = 100
A Better Solution for the Rental Ski Problem Rent&Buy • Rent for 10 days • 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 !!!!!!!!!!!
Solution of the Cow Fence Problem Deterministic Cow-Path • dir left • for i 0 to log n do • go 2i steps to direction dir • go 2i steps back to the origin • revert direction dir • od Theorem [Baeza-Yates, Culberson, Rawlins, 1993] The deterministic Cow-Path algorithm has a competitive ratio of 9. This competitive ratio is optimal.
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’/4 d’/2 Exit d’ 2d’ d’ 2d’ d’+1
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 ?
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... k2 1
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.
Thanks for your attentionEnd of 11th lectureNext 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