JavaScript Algorithms and Data Structures: Brute Force - Linear Search

Linear search is a brute force algorithm that searches for a target value in an array by sequentially comparing the target value to each element in the array. Learn how to implement linear search in JavaScript.

In computer science, linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.

Linear Search

Complexity

Time Complexity: O(n) - since in worst case we're checking each element exactly once.

References

The Original Article can be found on https://github.com

#javascript #algorithms #datastructures

JavaScript Algorithms and Data Structures: Brute Force - Linear Search
3.15 GEEK