Linear Search
Searchingeasy#8Check each element sequentially until target is found
Ready
Step 1 of 0
Speed
Input Data
Comma-separated numbers (0-999). Min 2 values.
Algorithm Code
1function linearSearch(arr, target) {2 for (let i = 0; i < arr.length; i++) {3 if (arr[i] === target) return i;4 }5 return -1;6}
Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(1)
About Linear Search
Linear Search sequentially checks each element of the list until a match is found or the whole list has been searched. It works on unsorted arrays and is the simplest search algorithm. Best suited for small datasets or unsorted collections.
Time Complexity: Best: O(1), Average: O(n), Worst: O(n). Space: O(1).