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)
View Linear Search Visualization