Linear Search Visualization & Animation

Scans every element one by one; works on any array but O(n) in the worst case.

## What is it? Linear Search scans every element of an array one by one until the target is found or the end is reached. It works on any array — sorted or unsorted. ## How it works - Start at index 0 - Compare each element with the target - If a match is found, return the current index - If the end is reached without a match, return -1 (not found) ## When to use - Unsorted arrays where Binary Search is not applicable - Very small arrays (n < 10) where overhead of sorting is not worth it - Searching in linked lists or streams where random access is not possible - One-time search (sorting first would cost more than the search itself) ## Key Points - Works on any sequence — sorted, unsorted, even streams - O(n) time — must check every element in the worst case - Simple to implement; zero preprocessing required - For repeated searches on the same data, sorting + Binary Search is more efficient

Category: algorithms

Difficulty: beginner

Time Complexity: O(n)

Space Complexity: O(1)

Linear Search

beginner

Scans every element one by one; works on any array but O(n) in the worst case.

10
[0]
20
[1]
30
[2]
40
[3]
50
[4]
60
[5]
70
[6]
Unvisited
Currently checking
Found
Not found
Starting linear search. Looking for 40 in array: [10, 20, 30, 40, 50, 60, 70]