Year9 Unit1 Lesson7 Worksheet1
Year9 Unit1 Lesson7 Worksheet1
Lesson 7
Worksheet 1
Binary searches
Solution 1
Solution 2
Solution 3
© Pearson Education Ltd 2019. Copying permitted for purchasing institution only. This material is not copyright
free.
Solution 4
OUTPUT “Which number do you want to find?”
INPUT user inputs 56
STORE the user’s input in the guess variable
guess_found = False
(we need to create a flag that identifies if the number is found)
WHILE guess_found = False:
Find midpoint of list
IF guess = record at midpoint of list THEN
guess_found = True
ELSE IF guess comes before the midpoint THEN
throw away the second half of the list
ELSE
throw away the first part of the list
OUTPUT guess
© Pearson Education Ltd 2019. Copying permitted for purchasing institution only. This material is not copyright
free.