Skip to content

Course home

Searching and sorting algorithms

Searching and sorting algorithms

EasyMedium
1234567891011121314151617
Question 6

The product codes for an inventory system are stored in an array with the identifier inventory.

Index01234567
Data"A10""B22""C35""D41""E59""F62""G73""H88"

A linear search function is used to check whether a product code is present in the inventory array. The function:

  • takes a product code as a parameter
  • returns True if the product code is found in the array
  • returns False if the product code is not found in the array.

Complete the design of the algorithm for this linear search function.

function findProduct(searchCode)
    for index = 0 to .....
        if inventory[.....] == ..... then
            return .....
        endif
    next index
    return False
endfunction
[4]
Markscheme

Searching and sorting algorithms Questions

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

36 exam-style questions on OCR GCSE Computer Science Searching and sorting algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank