1.3 searching algorithm
1.3 searching algorithm
Searching Algorithms
Contents
Linear Search
Binary Search
Comparing Linear Search & Binary Search Algorithms
Page 1 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Linear Search
Your notes
Linear Search
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
4 REPEAT UNTIL you have checked all values and not found the value you are looking for
Page 2 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
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
Your notes
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
Page 3 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Binary Search
Your notes
Binary Search
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
Page 4 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Example 1 - numbers
Perform a binary search to locate number 7 in the following dataset Your notes
Example 2 - words
Perform a binary search to locate the word "Rock" in the following dataset
Page 5 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Worked Example
Describe the steps a binary search will follow to look for a number in a sorted list [4]
Answer
Page 6 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Select / choose / pick middle number (or left/right of middle as even number) and …
…check if selected number is equal to / matches target number (not just compare)
…if searched number is larger, discard left half // if searched number is smaller, discard right half Your notes
Repeat until number found
… or remaining list is of size 1 / 0 (number not found)
Guidance
Can get a mark for bullet points 1 & 2 in one step (e.g. check if the middle value is the one we're
looking for")
# Set the initial low and high pointers to the beginning and end of the data
low = 0
high = len(data) - 1
# While the low pointer is less than or equal to the high pointer
while found is False and low <= high:
# If the target is less than the middle value, search in the left half of the data
elif data[mid] > target:
high = mid - 1
Page 7 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 8 of 8
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers