5

Let's assume I am trying to find a hidden treasure.

The treasure is hidden at an uknown position x. We know that the position x of the treasure is somewhere on the integer axis (in other words x is an integer). In order to find the treasure I have to take with me a detector. The detector can spot the treasure only if it is above it.

My starting position is the 0 point and I can move back and front until I cross the treasure, so that my detector can track it. I am always moving on the integer line. Which is the most efficient way to move through the axis in order to track the treasure?? I have to find an algorithm that allows me to find the treasure by covering a distance $O(|x|)$

My approach: After some consideration, I think that the most efficient way to find the treasure is the following: Starting from 0 I move front until I reach number $2$. Then I move back until I reach number $-2^2$. Then I move front until I reach number $2^3$. Then I go back again until I reach number $-2^4$ and so on...

However, I am having difficulties on proving that there is a constant $c$ (for which I have to calculate an upper bound) so that my algorithm is going to help me find the treasure at $c |x|$ moves at most. Any help is much appreciated! Thanks in advance!

P.S. I am new at the computer science stack exchange so I am not sure about the tags. Correct them or add more if necessary.

MJ13
  • 187
  • 1
  • 1
  • 7

3 Answers3

4

Your problem is known variously as the lost cow problem or the cow-path problem, and is a standard example in online algorithms. The algorithm you describe is 9-competitive, which is optimal for deterministic algorithms. For randomized algorithms the competitive ratio is roughly 4.6. See for example a writeup apparently by Rudolf Fleischer.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
2

I will suggest a similar strategy. Note that your strategy yields a constant factor better than the one presented here but the proof is more technical.

Let us divide the strategy in rounds $1, 2, \dots$, where in round $i$ we go $2^{i-1}$ steps to the right, then we go back to the center and we repeat the exact same to the left. This means we go one step to the right then back to the middle and one to the left and back again then two to the right and two to the left then 4 to the right and so on. The total number of steps is upper bounded by

$$4\sum\limits_{i=0}^{\left\lceil \log x\right\rceil} 2^i$$ $$\leq 4 \sum\limits_{i=0}^{\log x + 1} 2^i$$ $$\leq 4\sum\limits_{i=0}^{\log (2x)} 2^i$$ $$\leq 4 \cdot 2^{\log(2x)+1}$$ $$= 4\cdot 2^{\log(4x)}$$ $$= 16x,$$ where the factor 4 in the first line means going to the right $2^i$ steps then back to the center and repeating on the left side.

Narek Bojikian
  • 4,784
  • 1
  • 13
  • 36
0

Your approach is correct. Without loss of generality, suppose that $2^{2n-1} < x \le 2^{2n+1}$. Now, if you count the number of steps needed to find $x$ with your algorithm, you'll find out that it contains the sum of geometric progression which can be bounded by $2^{2n+3} = 16\cdot 2^{2n-1} = O(x)$ since $2^{2n-1} < x$.

diplo
  • 183
  • 1
  • 9