Menu

Search Algorithms

Search Algorithms

A search algorithm is a set of steps used to find out whether a particular item is present in a collection of data and, if it is, where it is located. The item you are looking for is called the target.

A search works by comparing the target with items in the list, following the algorithm's steps, until it finds a match or shows that the item is not there. Searching only looks at the data โ€” it never changes it. For example, searching a list of after-school clubs for Chess Club might report that it was found at position 2; if the club is not on the list at all, the search reports that it was not found rather than giving a position.

Successful or unsuccessful

A search that finds the target is successful and reports where the item sits in the list. A search that finishes without a match is unsuccessful and reports that the item is not there. The position is the place in the list, not the value stored at that place.

OutcomeWhat it meansWhat is reported
SuccessfulThe target was compared with an item and matchedThe position of the target in the list
UnsuccessfulNo comparison matched, so the target is not in the listThat the target was not found

Two search methods

There are two searching methods you need to know: linear search and binary search. Both can produce a successful or unsuccessful result and both compare a target with items in the data, but their steps are very different.

Practise this