Short answer: The egg dropping problem asks for the minimum number of trials that suffice, in the worst case, to find a critical floor with e eggs and f floors. Dropping at floor x leaves either e−1 eggs and x−1 floors below, if the egg breaks, or e eggs and f−x floors above, if it survives. The cell is one plus the minimum, over x, of the worse of those two subproblems. The table is O(e · f²) in the direct form. With two eggs the optimum is the triangular-number strategy.
What the problem actually asks
A binary search minimizes the number of drops when eggs are unlimited, because a broken egg is replaced. With a finite egg budget the search has to spend cheap drops low in the building so that a break does not exhaust the budget before the critical floor is isolated. The DP encodes that tradeoff. It does not simulate one building. It chooses a first drop that minimizes the worst branch.
The worst branch is a maximum inside the minimization. Swapping those two aggregators produces a strategy that is optimistic about the building and fails on the other branch.
What the algorithm guarantees
The cell dp[e][f] is the minimum number of drops that guarantees finding the critical floor. Base cases: one egg forces a linear scan, so dp[1][f] = f, and zero floors need zero drops. Time of the direct loop is Θ(e · f²). A reformulation that uses the number of drops as the state, and asks how many floors t eggs and d drops can cover, runs faster and is the usual way to compute the two-egg closed form. With two eggs and an optimal policy the maximum floors coverable in d drops is d(d+1)/2.
The critical floor is defined as the lowest floor from which the egg breaks, and it may be above the top floor, meaning the egg never breaks. The state count has to include that possibility, which the standard floor indexing does when f is the number of floors to distinguish.
The working steps
- Set dp[1][f] = f and dp[e][0] = 0. One egg walks floors one by one. No floors need no drops.
- For increasing egg counts and floor counts, set dp[e][f] to one plus the minimum over x of max(dp[e−1][x−1], dp[e][f−x]).
- The minimizing x is a first drop that attains the optimum. It is not always the middle floor when eggs are scarce.
- For two eggs, choose gaps that shrink by one: drop so the number of remaining drops covers the floors below with one egg and the floors above with two.
- Read dp[e][f] as the worst-case number of drops, not as the expected number under a uniform floor.
The quantity is a worst-case minimum, not an expectation. An average-case strategy under a known distribution over floors is a different DP. Unlimited eggs reduce the problem to binary search. The quadratic factor in f is the naive minimization. The drops-as-state formulation avoids it when only the numeric answer is required.
Approaches that look simpler and fail
| Approach | Why it fails when the inner aggregator is a sum or a minimum |
|---|---|
| Minimize the sum of the two branches | That optimizes an average of the branches, or a total, and a building that always takes the worse branch can exceed the claimed number of drops. |
| Always drop at the middle | With one spare egg that strategy can break the spare at a high floor and then scan a long interval. The DP moves the first drop down when eggs are scarce. |
| Use dp[1][f] = ceil(log f) | One egg cannot binary-search. A break ends the experiment, so the one-egg policy is linear. |
| Report the minimizing x as the critical floor | x is where the first experiment is made. The critical floor is what the experiments discover, and it depends on the outcomes. |
Unlimited eggs are binary search on the floors. A distribution over the critical floor wants an expected-cost DP, not this worst-case table. Egg dropping is the worst-case recurrence with a minimum of maxima.
A working example
This Python fragment limits the worst case of egg dropping. Two eggs and six floors need a plan whose minimum worst-case drops is 3.
eggs, floors = 2, 6
dp = [[0] * (floors + 1) for _ in range(eggs + 1)]
for f in range(1, floors + 1):
dp[1][f] = f
for e in range(2, eggs + 1):
for f in range(1, floors + 1):
dp[e][f] = min(
1 + max(dp[e - 1][x - 1], dp[e][f - x])
for x in range(1, f + 1)
)
assert dp[2][6] == 3
print(dp[2][6])
Where it is used
The egg-dropping recurrence is the worst-case cost of finding a critical floor with a limited number of destructive trials. Laboratories that break samples to find a threshold face the same shape. It is not a scheduler and it is not a sort.
When you can drop this algorithm
Drop the worst-case table when the loss function is an expectation under a known prior. Keep it when the guarantee required is a bound on the number of drops no matter which floor is critical.
Why this stays published
We publish this so a search for the egg dropping problem returns the min-of-max recurrence and the linear policy forced by one egg. Egg dropping computes the minimum number of trials that suffice in the worst case by a recurrence that minimizes, over the next floor, the worse of the break and survive branches.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
