Linear Search
Sequential search technique for finding a target element within a list.
What is Linear Search?
Linear search (also known as sequential search) is the simplest searching algorithm. It starts at the beginning of a dataset and inspects each element one by one until either a match is found or the end of the array is reached.
Advantages
- Works on unsorted arrays and datasets.
- No additional memory allocation required (O(1)).
- Simple implementation and low overhead for tiny datasets.
Limitations
- In-efficient on large datasets compared to O(log N) binary search.
- Worst-case scenario requires inspecting every item in memory (O(N) time).
- High average response latency for deep elements.
Algorithm Steps
// Pseudocode Representation
function linearSearch(arr, target):
for i from 0 to length(arr) - 1:
if arr[i] == target:
return i // Match found
return -1 // Target not in list