×
☰ Menu

Linear Search Algorithm

The linear search algorithm is also known as the sequential search algorithm. It is the most basic search algorithm. We just traverse the list in linear search and match each element of the list with the item whose position has to be discovered. If a match is found, the algorithm delivers the item's location; otherwise, NULL is returned.

It is widely used to search an element from the unordered list, i.e., the list in which items are not sorted.

 

Working of Linear Search

 

 

 

 

Algorithm of Linear search

Linear Search ( Array A, Value x)

Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit