Search Algorithms
A search algorithm is a method for finding out whether a target value is present in a collection of data and, if needed, where it is located. The collection could be the scores in a game, the booking references in a cinema system or the track titles in a playlist, and the target is the single value you are looking for.
Searching is a very common operation in programs. A quiz game might need to check whether a player's name is already on a leaderboard, a cinema app might need to find which screen a booking is for, or a school system might need to confirm that a pupil code is on a trip list. In each case the program needs a reliable, repeatable method rather than guessing, and it must also cope with the target not being there at all. A search that only works when the value exists is not finished: the program still has to give a correct answer when nothing matches.
For example, imagine a playlist stored as a list of track titles and you want to know whether Midnight Run is included. A search algorithm gives the program a set of steps to follow so that it can answer yes or no, and report the track's position when it is found.
The two standard search algorithms are linear search and binary search. They take different approaches and suit different situations, so a programmer chooses between them based on the data and what the program needs to do.
Edexcel GCSE Computer Science · Search Algorithms