DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

1

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay