9

Suppose that you have an $N$-story building and plenty of eggs. An egg breaks if it is dropped from floor $T$ or higher and does not break otherwise. Your goal is to devise a strategy to determine the value of $T$ given the following limitations on the number of eggs and tosses:


Version 0: $1$ egg, $\leq T$ tosses

Version 1: $\text{~}1$ $\text{lg}$$(N)$ eggs and $\text{~}1$ $\text{lg}(N)$ tosses. ($lg$ is log base 2)

Version 2: $\text{~}1$ $\text{lg}$$(T)$ eggs and $\text{~}2$ $\text{lg}$$(T)$ tosses

Version 3: $2$ eggs and $\text{~}$ $2\sqrt{N}$ tosses

Version 4: $2$ eggs and $\text{~}$ $\sqrt{2N}$ tosses

Version 5: $2$ eggs and $\leq$ $2\sqrt{2T}$ tosses


I think I have the answer for most of these but don't know how to do a few. Could you please check over my work and provide hints on how to approach the ones I don't know how to do?


For version 0, a simple iterative search starting from the 1st floor and working up to the $N$th floor in increments of 1 will work.

For version 1, a binary search across the floors $1$ to $N$ will work.

For version 2, I think you can iteratively double floors, visiting $1$, then $2$, then $4$, then $8$, etc. until the egg breaks at floor $2^k$. Then you can binary search across $2^{k-1}$ and $2^k$

For version 3, you can go iteratively go across floors with incrementing by $\sqrt{N}$: first visiting 0, then $\sqrt{N}$, then $2\sqrt{N}$, etc. Once the egg breaks at stage $k\sqrt{N}$, iterate across the range $(k-1)\sqrt{N}$ and $k\sqrt{N}$ one floor at a time.

For versions 4 and 5 I don't know how to start. Can someone please provide a hint?

achille hui
  • 122,701
1110101001
  • 4,188

3 Answers3

3

(Version 5: 2 eggs and ≤ 2*sqrt(2)*sqrt(T) tosses)

Drop eggs from floors, 1, 3, 6, 10, 15 and so on.. (3 = 1 + 2, 6 = 1+ 2 + 3, 10 = 1 + 2 + 3 + 4 etc.

Let us say the first egg breaks at floor 21 (that's 1 + 2 + 3 + 4 + 5 + 6). This tells us that T is between 15 and 21. Till now, we have had 6 tosses.

Now, 1 + 2 + 3 +.....t = t(t+1)/2 which can be approximated to t^2/2 for ease of calculation of t is large. So, the floors at which we have been tossing eggs actually are approx. t^2/2 where t is the number of tosses so far.

So, let us come back to the example above for clarity. Here t = 6 and t(t+1)/2 (without any approx.) = 21. So, till now we have had t tries. Now, the next step is to keep tossing eggs sequentially from 16 to 21 till the 2nd egg breaks and we find T out.

The worst case scenario for T is 21 as in that case we'll have to keep breaking eggs till we reach 21. Or, we could generalize and say that the worst case scenario for T is t(t+1)/2 (approx. t^2/2) where t tries have been completed. So t = approx. sqrt(2)*sqrt(T).

Total number of tosses required in reaching floor 21 (assuming that's T in the worst case) will be tosses to reach floor 21 (6) + tosses from 16 to 21 (6 again).

Basically, the total number of tosses required in reaching floor T will be t - to reach the upper bound of T (21 in this case) PLUS sequential tries from the floor before t(t+1)/2th floor.

Now t th toss' floor is t(t+1)/2 t-1 th toss' floor is t(t-1)/2 (that's what 1 + 2 + 3 +.... (t-1) is).

The difference between the two turns out to be t (that means t(t+1)/2 - t(t-1)/2 is t).

So, the maximum number of sequential tries from t(t-1)/2 th floor to t(t+1)/2 th floor is t.

Hence, the final maximum number of tosses in reaching floor T = tosses in reaching floor t(t+1)/2 + sequential tries from t(t-1)/2 th floor to t(t+1)/2 th floor.

So, maximum tosses required = t + t = 2t.

But t = sqrt(2)*sqrt(T).

So, 2t = 2*sqrt(2)*sqrt(T) = maximum tosses required to reach floor T.

3

A very broad hint for version 4: consider that in your version-3 answer you don't have to use uniform intervals between drops of the first egg. Can you see how to use a non-uniform distribution so that the worst-case total is identical no matter where the first egg breaks?

2

For the fifth, take intervals $1,2,3,\cdots$ and then it iterate through the unknown elements. This achieves the desired bound since solving $$\frac{n(n+1)}2=T\implies n\le\sqrt{2T}$$ Yields that the first egg will be thrown at most $\sqrt{2T}$ times. Being the last interval $\sqrt{2T}$, the second egg will be thrown(at most) the same number of times.

chubakueno
  • 5,623
  • So you are saying that you go like floor 1, 2, 4, 7, 11, 16, etc...? How did you get $\frac{n(n+1)}{2} = T$? – 1110101001 Jun 16 '14 at 05:40
  • I was going like $1,2,3,6,10,\cdots$ but that works too. If you take a look a the $n$th term of your series is $\frac{n(n+1)}2+1$. For the $n$th to exceed $T$ for the first time, you get that $n\le \lceil\sqrt{2T-2}\rceil$. Then, with the second egg, you iterate incrementally through those possible $n-1$ elements. – chubakueno Jun 16 '14 at 14:59
  • Your answer is only correct for n = 2 eggs. n. eggs has a different solution explained pretty well here http://www.geeksforgeeks.org/dynamic-programming-set-11-egg-dropping-puzzle/ – Will Jul 20 '15 at 02:58