-3

I do not know what to do next (and even if my approach is correct) in the following problem:

Part 1 Part 2

I have just figured out that a possible MNT (for part a) is to get a jar, test if it breaks from height h, if so then there's the answer, if not, height+1 and keep looping.

For part b is the following. Since we know max height equals n, then we start from n (current height = n). Therefore we go from top to bottom adding to our broken jar count (they are supposed to break if you start from top) until the jars stop breaking. Then the number would be current height + 1 (because we need to go back one index).

For part c, I don't even know what my approach would be, since I am assuming that the order of the algorithm is O(n^c) where c is a fraction. I also know that O(n^c) is faster than O(n).

I also noted that there is a problem similar to this one online, but it talks about rungs instead of a robotic arm. Maybe it is similar? Here is the link

Do you have any recommendations/clues? Any help will be appreciated.

Thank you for your time and help in advance.

Cheers!

Community
  • 1
  • 1
  • 4
    Please don't link to external images - external sites can go down, and your question won't have any meaning then. – Ami Tavory Sep 19 '16 at 13:23
  • What's the source of this problem? We require that you [properly credit your sources](http://cs.stackexchange.com/help/referencing). The problem seems to be identical to problem 3 in [CS560 Assignment #1](http://www-rohan.sdsu.edu/~tarokh/lab/CS560-Sp11/Assignments/CS560-Assignment1.doc) from SDSU. Please provide attribution. See also http://cs.stackexchange.com/q/63643/755. – D.W. Sep 20 '16 at 11:59

2 Answers2

0

This is an answer for part (c). The idea is to find some number k and apply the following scheme: Drop a jar from height k:

  • If it breaks, drop the other one from k-1 down to 1 until we find the height that it breaks in, in no more than k tries.
  • If it doesn't break, drop it again from height k + (k-1). Again, if it breaks drop the other one from (k+(k-1)-1) down to k+1, otherwise continue to (k + (k-1) + (k-2)).
  • Continue this until you find the height

(of course if at some point you need to jump to a height greater than n, you just jump to n).

This scheme ensures we'll use at most k tries. So now the question is how to find a minimal k (as a function of n), for which the scheme will work. Since, at every step, we reduce by 1 our height advancement, the following equation must hold:
k + (k-1) + (k-2) + ... + 1 >= n
Otherwise will "run out" of steps before reaching n. We want to find the smallest k for which the inequality holds. There's a formula to the sum:

1 + 2 + ... + k = k(k+1)/2

Using that we get the equation:

k(k+1)/2 = n ===> k^2 + k - 2n = 0

Solving this (and if it's not integral take the ceiling of it) will give us k. Quadratic equations might have two solutions, but ignoring the negative one you get:

k = (-1 + sqrt(1 + 8n))/2

Looking for the complexity, we can ignore everything but the n, which has an exponent of 1/2 (since we're taking its square root). That is actually better then the requested complexity of n to power of 2/3.

Yuval
  • 110
  • 6
  • By the way, this is famous riddle, usually asked about two eggs and a 100 story building. Applying the formula with n = 100, we get k = 14. – Yuval Sep 19 '16 at 14:51
-1

For part (a) you can use binary search over height. pseudo code for the same is below :

lo = 0
hi = n
while(lo<hi) {
   mid = lo +(hi-lo)/2;
   if(galss_breaks(mid)) {
        hi = mid-1;
   } else {
        lo = mid;
   }
}

'lo' will contain the maximum possible height in minimum possible trials. It will take log(n) steps in worst case whereas your approach may take N steps in worst case.

For part(b) ,

you can use your approach a, start from the minimum height and increase height by 1 until the glass breaks. This will at most break 1 glass to determine the required height.

sourabh1024
  • 647
  • 5
  • 15