Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Egg problem confusion

Tags:

algorithm

Two Egg problem:

  • You are given 2 eggs.
  • You have access to a 100-storey building.
  • Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.
  • You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.
  • Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process

I am sure the two egg problem ( mentioned above ) has been discussed sufficiently. However could someone help me understand why the following solution is not optimal.

Let's say I use a segment and scan algorithm with the segment size s. So,

d ( 100 / s   + (s-1) ) = 0    [ this should give the minima,  I need '(s-1)' scans per segment and there are '100/s' segments]
-
ds

=> -100 / s^2 + 1 = 0
=> s^2 = 100
=> s = 10

So according to this I need at most 19 drops. But the optimal solution can do this with 14 drops.

So where lies the problem?

like image 257
Rohan Monga Avatar asked Nov 13 '10 10:11

Rohan Monga


People also ask

What is the solution to the problem with 100 storeys and 2 eggs?

Drop the egg from the first-floor window; if it survives, drop it from the second-floor window. Continue upward until it breaks. In the worst case, this method may require 100 droppings.

Which floor egg will not break?

The Problem One of the floors is the highest floor an egg can be dropped from without breaking. If an egg is dropped from above that floor, it will break. If it is dropped from that floor or below, it will be completely undamaged and you can drop the egg again.

What is the egg drop problem?

Egg dropping refers to a class of problems in which it is important to find the correct response without exceeding a (low) number of certain failure states. In a toy example, there is a tower of n floors, and an egg dropper with m ideal eggs.

How do you have two eggs?

There are two ways that a woman may conceive twins. In one case, her ovaries release two eggs at the time of ovulation, and both are fertilized and become embryos; this results in fraternal, or nonidentical, twins. In contrast, identical twins are conceived when one embryo splits into two early in its development.


1 Answers

You seem to be assuming equal-sized segments. For an optimal solution, if the first segment is of size N, then the second has to be of size N-1, and so on (because when you start testing the second segment, you've already dropped the egg once for the first segment).

like image 67
Jerry Coffin Avatar answered Sep 30 '22 01:09

Jerry Coffin