Learn how the Linear search Algorithm works and how to implement it .
Linear search is a Searching algorithm, which is used to check if an element is present in an array or list . It is also called Sequential search.
A linear search sequentially search for the target element in the array. If it finds the element in the array it stop searching and returns successful . If it reaches the end of the array, then it returns element not found.
Algorithm
-
Traverse the array using a
forloop (any looping technique). -
In every iteration, compare the
targetvalue with the current value of the array.
- If the values match, return the current index of the array.
- If the values do not match, move on to the next array element.
3. If no match is found, return element not found.
Code can be found here.
Thanks for Reading 📖 . Hope you like this. If you found any typo or mistake send me a private note 📝 thanks 🙏 😊 .
Follow me JavaScript Jeep🚙💨 .
Please make a donation here. 80% of your donation is donated to someone needs food 🥘. Thanks in advance.
