| Tutorial ID | 102 |
|---|---|
| Title | Sequential Search |
In computer science, linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found.[1] Linear search is the simplest search algorithm; it is a special case of brute-force search. Its worst case cost is proportional to the number of elements in the list; and so is its expected cost, if all list elements are equally likely to be searched for. Therefore, if the list has more than a few elements, other methods (such as binary search or hashing) will be faster, but they also impose additional requirements.
Pseudocode For each item in the list:
if that item has the desired value,
stop the search and return the item's location.
Return false.
In this pseudocode, the last line is executed only after all list items have been examined with none matching.
Otherwise, the position of the first item matched is returned.
Reference: Wikipedia | |
Facebook