Linear Search (AQA GCSE Computer Science)

Revision Note

Test yourself
James Woodhouse

Written by: James Woodhouse

Reviewed by: Lucy Kirkham

What is a searching algorithm?

  • Searching algorithms are precise step-by-step instructions that a computer can follow to efficiently locate specific data in massive datasets

  • Two common searching algorithms are:

    • Binary search

    • Linear search

  • A linear search starts with the first value in a dataset and checks every value one at a time until all values have been checked

  • A linear search can be performed even if the values are not in order

Step

Instruction

1

Check the first value

2

IF it is the value you are looking for

  • STOP!

3

ELSE move to the next value and check

4

REPEAT UNTIL you have checked all values and not found the value you are looking for

Examiner Tips and Tricks

You will not be asked to perform a linear search on a dataset in the exam, you will be expected to understand how to do it and know the advantages and disadvantages compared to a binary search

Worked Example

A linear search could be used instead of a binary search.

Describe the steps a linear search would follow when searching for a number that is not in the given list [2]

Answer

  • Starting with the first value

  • Checking all values in order

Guidance

  • Must cover idea of checking all value AND being done in order!

  • "Checks each value from the beginning to the end" implies order so would get both bullet point 1 & 2

A linear search in python

# Identify the dataset to search, the target value and set the initial flag
data = [5, 2, 8, 1, 9]
target = 11
found = False

# Loop through each element in the data
for index in range(0,len(data) - 1):
  
  # Check if the current element matches the target
  if data[index] == target:
    67
    # If found, output message
    found = True
    print("Target found")

#If the target is not found, output a message
if found is False:
  print("Target not found")

Last updated:

You've read 0 of your 10 free revision notes

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.

Lucy Kirkham

Author: Lucy Kirkham

Expertise: Head of STEM

Lucy has been a passionate Maths teacher for over 12 years, teaching maths across the UK and abroad helping to engage, interest and develop confidence in the subject at all levels.Working as a Head of Department and then Director of Maths, Lucy has advised schools and academy trusts in both Scotland and the East Midlands, where her role was to support and coach teachers to improve Maths teaching for all.