A programmer is designing a search system for a fruit inventory. The system uses a binary search algorithm to locate items.
Here is the algorithm's pseudocode:
fruits = ["Apple", "Banana", "Cherry", "Fig", "Grape", "Lemon", "Mango", "Peach"]
fruitToFind = input("Enter fruit name: ")
found = False
start = 0
finish = 7
while found == False and start <= finish
mid = (start + finish) DIV 2
if fruits[mid] == fruitToFind then
found = True
else if fruitToFind > fruits[mid] then
start = mid + 1
else
finish = mid - 1
endif
endwhile
Complete the trace table below for this algorithm if the user inputs "Mango".
The first row has already been set up for you.
| fruitToFind | found | start | finish | mid |
|---|---|---|---|---|
| "Mango" | False | 0 | 7 | 3 |
33 exam-style questions on AQA GCSE Computer Science Searching algorithms. Each one has a worked solution and a mark scheme showing where the marks go.