Scans the array left to right, comparing each element to the target until it's found.
Scans the array left to right, comparing each element to the target until it's found.
Time complexity: O(n). Space complexity: O(1).
Core idea — Check elements one by one from left to right until the target turns up.
What each pass accomplishes — Each step compares exactly one element to the target: a match ends the search, otherwise you move one position right. After k steps you know the target isn't in the first k elements.
Use the interactive visualizer above to run Linear Search on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.