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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay