Two egg dropping puzzle variation: unknown/infinite floors

后端 未结 2 1033
忘了有多久
忘了有多久 2021-01-27 10:50

Preface

This problem was inspired by a similar question last week on SO, that got deleted before it was clear what the real question was. I think this

相关标签:
2条回答
  • 2021-01-27 11:26

    The sub-optimal solution for the infinite problem for two eggs is to use the sequence 1, 2^2, 3^3,... ,i^2,... and start the second edge where the last value the first egg remains. So if the first edge remains at n^2, then the next one will do at most 2*n + 1 - 1 (minus 1 from the first) test to give the total of 3 * n in the worst case with n = sqrt(m).

    0 讨论(0)
  • 2021-01-27 11:40

    There is a simple method that has O(sqrt(f*)) complexity. Make your nth step to be n floors up, that is, check floors 1, 3 (1 + 2), 6 (1 + 2 + 3), etc. This way at the nth step you will be on n*(n+1)/2 floor, and you will reach f* in n = O(sqrt(f*)) steps.

    Then for the second egg you will need to go n single steps over your last step in stage 1, which will add another O(sqrt(f*)).

    If O(sqrt(k)) was optimal for known k, this method has to be optimal in terms of complexity, too.

    0 讨论(0)
提交回复
热议问题