Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 16

An astronomer is designing a search system for a stellar database. The system uses a binary search algorithm to locate constellations by name.

Here is the algorithm's pseudocode:

constellations = ["Andromeda", "Aquila", "Cygnus", "Gemini", "Lyra", "Orion", "Pegasus", "Taurus", "Ursa"]
target = input("Enter constellation name: ")
found = False
start = 0
finish = 8

while found == False and start <= finish
    mid = (start + finish) DIV 2
    if constellations[mid] == target then
        found = True
    else if target > constellations[mid] then
        start = mid + 1
    else
        finish = mid - 1
    endif
endwhile

Complete the trace table below for this algorithm if the user inputs "Orion".

The first row has already been set up for you.

targetfoundstartfinishmid
"Orion"False084
[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