Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 8

Complete the trace table for the program in Figure 1 if the user input is sodium.

Part of the table has already been filled in.

You may not need to use all the rows in the table.

Figure 1

elements = ["argon", "boron", "copper", "helium", "neon", "oxygen", "sodium", "zinc"]
elementToFind = input("What element would you like to find? ")
found = False
low = 0
high = len(elements) - 1
while found == False and low <= high:
    mid = (low + high) // 2
    if elements[mid] == elementToFind:
        found = True
    elif elementToFind > elements[mid]:
        low = mid + 1
    else:
        high = mid - 1
print(found)
elementToFindfoundlowhighmid
sodiumFalse073
[3]
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