DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

Linear search algorithm

Lets see when can we use and what is the linear search algorithm for.

Lets say that we want to find an array a the index of an specific value we can do it with linear search when the array that we want to found is not something enormous, cause when the array is something gigantic we will want to use binary search but for now lets stay with linear search and lets see an example of it.

Image description

In the example above we can see that it will just return the index of the value given which in this case will be a, and the b value will be the array where we want to found the specific value.

If we also want to get the value of the specific index which should be the same as the given to the function we can just simple add a new variable to store the value and return it with the position value.

Hope someone found it interesting or helpful.

Lautaro

Top comments (0)