Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Searching and sorting algorithms

Linear search

Standard searching algorithms: Linear search

2.1.3 Searching and sorting algorithms

Practise exam questions

Searching and sorting algorithms — Note 2 of 5

Understand the main steps of each algorithm, Understand any pre-requisites of an algorithm, Apply the algorithm to a data set, Identify an algorithm if given the code or pseudocode for it

What you need to know

Linear search is a simple searching algorithm that checks each item in a list one by one, starting from the first item, until the target is found or the end of the list is reached. It works on both sorted and unsorted lists, making it versatile but slower than binary search for large datasets.

What to know

  • Linear search starts at the FIRST item and checks each item ONE BY ONE, IN ORDER.
  • It works on any list, whether sorted or unsorted — no pre-requisites needed.
  • The algorithm stops as soon as the target item is found to avoid unnecessary work.
  • If the item is not found after checking every element, the search returns False / -1 or 'not found'.
  • Simple to understand and implement. When you compare it with binary search, say it is 'simpler to program'; 'easier to use' is not credited.
  • Slow for large lists, especially if the item is near the end or not present at all.
  • Also called sequential search.
  • A linear search can also be written without a function by using a FOUND FLAG: set found = False before the loop, set it to True when a match is found, then check it after the loop.

Code examples

Linear search (OCR Exam Reference Language)
text
function linearSearch(data, size, target)
    for i = 0 to size - 1
        if data[i] == target then
            return i      // found at index i
        endif
    next i
    return -1             // not found
endfunction

array numbers = [15, 7, 3, 5, 13, 8]
print(linearSearch(numbers, 6, 13))   // outputs 4
print(linearSearch(numbers, 6, 6))    // outputs -1
Linear search in Python
python
def linear_search(data, target):
    for i in range(len(data)):
        if data[i] == target:
            return i  # Found at index i
    return -1  # Not found

numbers = [15, 7, 3, 5, 13, 8]
print(linear_search(numbers, 13))  # Output: 4
print(linear_search(numbers, 6))   # Output: -1
Linear search with a found flag (OCR Exam Reference Language)
text
array scores = [12, 7, 5, 10, 3, 2, 7]
target = 7        // the value we are searching for
found = False     // flag: nothing found yet

for i = 0 to 6    // check each item IN ORDER (7 items: indexes 0 to 6)
    if scores[i] == target then
        found = True      // set the flag when a match is found
    endif
next i

if found == True then     // checked AFTER the loop
    print("Found")
else
    print("Not found")
endif
// this version checks every item; a version that stops at the first match uses a while loop or returns from a function
Linear search with a found flag
python
scores = [12, 7, 5, 10, 3, 2, 7]
target = 7       # the value we are searching for
found = False    # flag: nothing found yet

for i in range(len(scores)):   # check each item IN ORDER
    if scores[i] == target:
        found = True           # set the flag when a match is found

if found:                      # checked AFTER the loop
    print("Found")
else:
    print("Not found")

Exam technique

  • Tip:A common exam pattern is to iterate through an array using a for loop with the counter as the array index: prices[count].
  • Tip:When describing a linear search for an item NOT in the list, say it checks all values in order from start to end — don't say 'until found' since it won't be found. It stops when it reaches the END of the list: 'not found' on its own is not a condition a program can test.
  • Tip:'Checks each value' is not precise enough — you must state they are checked IN ORDER (sequentially).
  • Mistake:Putting else: print("Not found") inside the loop prints 'Not found' once for every item that doesn't match. Only decide 'not found' AFTER every item has been checked.

Ready to test yourself?

Practise 2.1.3 questions
← Previous noteBinary search2.1.3 Searching and sorting algorithmsNext note →Bubble sort2.1.3 Searching and sorting algorithms

Back to Searching and sorting algorithms

Revise another OCR GCSE topic: Designing, creating and refining algorithms

Searching and sorting algorithms

Note 2 of 5

  1. 1Binary search
  2. 2Linear search
  3. 3Bubble sort
  4. 4Merge sort
  5. 5Insertion sort
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).