Devising a Plan: Strategy

Develop a strategy to solve the problem.

We'll cover the following

Strategy

We need to figure out a strategy to find the correct number in the given range of numbers. However, first, we need to think of a way to find a number out of the 50 numbers with minimal guesses.

Can we use random guesses?

Guessing 20 will give one of the three possible outputs. Either we would guess the number correctly, or the number would lie in the range of either 1–19 or 21–50. We need to keep the following questions in mind while making guesses:

  • Do we have to be specific while guessing the number?

  • Is there any pattern in our guesses?

Guessing 25 divides the range into two almost equal ranges, 1-24 and 26-50.

We’ve gathered all the information from the problem statement, and now we need to develop a pattern of guesses to achieve our goal. However, we do not know how to do that.

It’s important to ask ourselves if we’ve encountered such problems before.

We see problems similar to this daily, like finding a specific item (e.g., keys, phone, or glasses) in our houses.

Is there any specific strategy to solve this number-guessing game? We can divide the problem into smaller parts, solve each part independently, and then merge the solution to solve the bigger problem.

We can break our problem up like this:

  • We can start with the middle number (25) in the given range as our initial guess.
  • Based on the computer’s hint, we can divide the search range in half:
    • If the hint is higher, we have a new updated range.
    • If the hint is lower, we have another specific range of numbers.

Get hands-on with 1400+ tech skills courses.