Pickles AcademyStart for free

Binary search – practice for Years 7–9

Sample questions on Binary search with the right answer and a worked solution, from easy to hard. In the Pickles Academy app a child gets new questions of the same kind every time, so they can't just learn the answers by heart.

Subject
Computing
Year
Years 7–9
Curriculum area
Information systems

Question types: Guessing a number by halving

Rule: Binary search

Always guess the middle of the numbers that are left. Each answer rules out about half.

n guesses are enough when 2ⁿ − 1 is at least how many numbers there are: 7 numbers 3 guesses, 15 numbers 4, 1000 numbers 10.

Example: 1 to 100: 2⁷ − 1 = 127 is enough, 2⁶ − 1 = 63 is not → at most 7 guesses

Watch out: Don’t guess one by one from the start: with 100 numbers it could take almost 100 guesses.

Sample questions

  1. Question 1 Easy

    I am thinking of a whole number from 1 to 31. To each guess I answer “higher”, “lower” or “correct”. How many guesses do you need at most if you always guess the middle of the numbers that are left?

    Show the solution
    Answer: 5

    How it works: Each guess at least halves what is left: 2^4 = 16 ≤ 31 < 2^5 = 32, so 5 guesses.

  2. Question 2 Normal

    I am thinking of a whole number from 1 to 530. To each guess I answer “higher”, “lower” or “correct”. How many guesses do you need at most if you always guess the middle of the numbers that are left?

    Show the solution
    Answer: 10

    How it works: Each guess at least halves what is left: 2^9 = 512 ≤ 530 < 2^10 = 1024, so 10 guesses.

  3. Question 3 Hard

    I am thinking of a whole number from 1 to 80. To each guess I answer “higher”, “lower” or “correct”. You always guess the middle of the numbers that are left (the smaller of the two middle ones when their count is even). With which guess do you hit 54?

    Show the solution
    Answer: 7

    How it works: Guesses: 40, 60, 50, 55, 52, 53, 54.

All Computing topics

Keep practising in the app

In a minute, your child has their own avatar and a first task. Free, no ads, data in the EU.

Start for free