Youre doing some stresstesting on various models of glass ja

You\'re doing some stress-testing on various models of glass jars to determine the height from which they can be dropped and still not break. The setup for this experiment, on a particular type of jar, is as follows You have a ladder with n rungs, and you want to find the highest rung from which you can drop a copy of the jar and not have it break. We call this the highest safe rung It might be natural to try binary search: drop a jar from the middle rung, see if it breaks, and then recursively try from rung n/4 or 3n/4 depending on the outcome. But this has the drawback that you could break a lot of jars in finding the answer If your primary goal were to conserve jars, on the other hand, you could try the following strategy. Start by dropping a jar from the first rung, then the second rung, and so forth, climbing one higher each time until the jar breaks. In this way, you only need a single jar-at the moment

Solution

This problem is slight variation of egg-stairs dynamic programming. So, when we drop a jar from a rung then there are two possible options:

1. If jug breaks from xth rung then we have to check for x-1 floors i.e., lower than x. So the probelm reduces to k-1 jugs and x-1 rungs.

2. If jug doesn\'t break from the xth rung then we have to check for n-x rungs. So, problem reduces to k jugs and n rungs.

Since, we need to minimize the number of jugs in worst case and along with that we need to find maximum rungs in above 2 cases which yield the minimum no. of trials.

So, function will be like:

jugDrop(k, n) = 1 + min {max(jugDrop(k - 1, x - 1), eggDrop(k, n - x)):

Hope it helps.

 You\'re doing some stress-testing on various models of glass jars to determine the height from which they can be dropped and still not break. The setup for thi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site