News for hackers. Stuff that matters.
Re:Steve Ballmer's incorrect binary search interview question by sltkr on Tuesday September 03, 2024 @10:53AM (#41435547)
Your logic is correct but you are off-by-one. 1 guess gets you 1 number, so the formula is 2^k - 1, and 7 guesses thus covers 127 numbers.

You can also view it as a recurrence:

  f(1) = 1
  f(n) = 2*f(n - 1) + 1 = 2^n - 1
But your binary search tree example is more intuitive.
Re:Steve Ballmer's incorrect binary search interview question by hulium on Tuesday September 03, 2024 @11:01AM (#41435622)
Yes, you are right. In this game, you can know the answer after 6 guesses, but then you also have to tell him, which counts as the 7th guess.