Linear array search
Very often you need to find a given value in an array or report that it is not there. To do this, you need to look through all the elements of the array from the first to the last. As soon as an element equal to the given value
X
is found, the search should end and the result should be displayed. Such an algorithm is called
linear.
A linear algorithm is used to find the maximum (minimum) element of an array. This is also a search algorithm. But here we are forced to go to the end of the array, because it is necessary to compare all elements with the current maximum (minimum) value and if the current element is greater (less) than the maximum (minimum) value, replace the maximum (minimum) value.