What Is a Linear Search?
A linear search looks for an item in a list. It checks each item in turn, starting at the first, until it finds the item being searched for (the target) or reaches the end of the list.
Interactive Demo
Watch a Linear Search
Items checked 0
Key points
- Check each item in turn, from the first item, until the target is found or the end of the list is reached
- Best case: the target is the first item. Worst case: the target is last or not in the list
- The list does not need to be sorted
Try It
Interactive Practice
Match or No Match
Is the highlighted item the same as the target?
Items checked 1
Right first time 0 / 0
Interactive Practice
Complete the Search
Work out the whole search, then fill in the boxes.
Searches right 0 / 0
The Algorithm
In the exam, a linear search may be shown as code or in OCR Exam Reference Language. You don't need to remember it, but you must recognise it and explain what each part does. Click a line to see what it does, or step through it.
Interactive Demo
Run the Code
target
i
found
list
Output: –
How to spot a linear search
- A loop that goes through the items one at a time, using an index such as i
- An if statement that compares list[i] with the target
- A flag such as found, or a result that is output when there is a match
- It may be written with a for loop or a while loop
Sample Questions
Write your answer, then reveal the mark scheme and tick each point you included.
Interactive Practice
Write & Mark
Interactive Practice
Complete the Explanation
Choose the right word for each gap.
Linear Search Challenges
Complete
0
Points
0
Challenge