3. THE PROBLEM
We have 2 eggs and a 100 floors
What is the min attempt? (worst case)
3
4. DEFINITION
We have k numbers of eggs and a building with n floors.
What is the least number of egg-dropping attempts that
is guaranteed to find the highest floor from witch the
egg won’t break on dropping?
4
5. NOTES
What strategy minimizes the number of attemps?
We can break the eggs during attempts
No tipping point exist! (mathematical sol’n)
5
6. TRIVIAL PROBLEMS
given one egg and ten floors
What is min attempt? (worst case)
Ans: 10
given ten egg and one floors
What is min attempt? (worst case)
Ans: 1
6
8. BACKTO MAIN
2 eggs and a 100 floors
Idea: 10 floors interval
Worst case?
19 attempt for 99
10,20,…,100 (10 att) + 91,…,99 (9 att)
8
9. ANOTHER STRATEGY
Idea: bigger intervals
e.g. size of intervals = 12
Worst case?
19 attempts for 95
12,24,...,84,96 (8 att) + 84,…,95 (11 att)
9
10. NOTE
In two last strategy:
Attempts are not identical for different numbers
e.g. 2 eggs, 100 floors:
for 24, 8 att & for 80, 9 att
10
11. BETTER STRATEGY
Idea: change intervals
Decreasing from x to 1 (optimizing x)
x + (x-1) + (x-2) + (x-3) + (x-4) + … + 1 >= n
For 10 floors x is 4
For 100 floors x is 14
11
14. DYNAMIC PROGRAMMING
We call Drop(n,k) recursively
Basic cases:
- Drop(1,x)=1
- Drop(x,1)=x
floor we are currently attempting to drop from is
represented by f
14
15. DYNAMIC PROGRAMMING
If we drop an egg from floor f, one of two events happens:
- Case 1: egg breaks:
our problem is reduced to a tower of height f-1, and we now
have k-1 eggs
- Case 2: egg doesn’t break:
we need to check n-f floors and we still have k eggs
15