Linear Search Algorithm
For Complete YouTube Video: Click Here
In this class, we will try to understand the Linear Search Algorithm.
In our previous classes, we discussed different types of sorting algorithms.
Linear Search Algorithm
Before understanding the linear search, we will discuss the working mechanism.
As shown below, we will consider the array to understand the working mechanism of the linear search.
The linear search is very straightforward to understand.
The element to be searched for gets compared with each element of the array.
If the element searched equals the array’s element, then the element’s index will be returned.
If not, we will compare all the elements of the array.
The algorithm for the linear search is shown below.
In the above algorithm, the for loop will iterate for n times.
We will compare each array’s element with the searching element in each iteration.
If it is true, the index of the element will get returned.