This problem can be solved by the following three approaches (what I know):
- Dynamic programming
- Binary Search Tree Solution
- The solution is by obtaining a direct mathematical formula for the maximum number of floors that can be checked or covered with a given number of eggs and a given number of drops
Let me first identify some of the characters that are used in the following analysis:
e = number of eggs f = number of floors in building n = number of egg drops Fmax(e, n) = maximum number of floors that can be tested or covered with e eggs and n drops
The principle of dynamic programming lies in the following recursive formula for Fmax:
Fmax(e, n) = 1 + Fmax(e-1, n-1) + fmax(e, n-1)
And the essence for obtaining a direct mathematical formula for Fmax is the following recursive formula for Fmax:
Fmax(e, n) = { βFmax(e-1,i) for i = 1 to n } - Fmax(e-1, n) + n
An alternative solution using a binary search tree (BST) is also possible for this problem. To facilitate our analysis, we will make a BST with minor changes as follows:
1. If egg breaks then child node is drawn on left down side 2. If egg does not break then child node is drawn straight down side
If we draw a BST with this view, then the width of the BST represents the number of eggs.
Any BST with f number of nodes drawn with this kind of representation and subject to the width of the restriction BST <= e (number of eggs) is a solution, but it may not be the optimal solution.
Therefore, obtaining the optimal solution is equivalent to obtaining the location of nodes in the BST with a minimum height that falls under the restriction: the width of BST <= e
For more information on all of the above three approaches, check out my blog at: 3 Approaches to Solving the Generalized Ovipositor Problem
Rushikesh
source share