Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 21

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.

fruitToFindfoundstartfinishmid
"Mango"False073
[4]
Markscheme

Searching algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Searching algorithms

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.

Question bank