Linear Search
Linear Search
Linear search is a sequential searching algorithm that is we start from one end and check each element of the list until the desired element is found. It is the simple searching algorithm.
In Linearsearch, traverse the list completely and match every element of the list with the element whose location is to be found. If the match is found, then the location of item is returned; otherwise, the algorithm returns NULL.
The steps used in the implementation of LinearSearch are listed are given below –
-
- Firstly, w traverse the array elements using a for loop.
- In each iteration of for loop, compare the search element with the current array element
- If matches the element, then return the index of the corresponding array element.
- If the element does not match, then move to the next element.
- If there element no match and the search element is absent in the given array, return -1.
Algorithm