Oh My Algorithm
Algorithm Guidecomplexity: O(n)

Linear Search

The most basic search method: checks every element in order from the start of the array until it finds the target.

01Linear Search

Starting linear search. We scan the array from the front, one by one, to find the target 34.

The first value, 45, is not the target. Step one slot to the right.

The next value, 12, isn't it either. Keep moving right.

89 is not the target either. Scanning from the front leaves nothing to skip.

The fourth value is 34 — a match. The search stops here.

Search complete · 34 sits at index 3. It works even on unsorted data, but slows down as the array grows.

45
12
89
34
67
23
56
10
1 / 6

02 Understand It Simply

For Everyone
🔑How It Works

Compares values one at a time from the front. The data need not be sorted, but the worst case looks at all of it.

💡In Plain Words

Compares elements one by one from the front to find the target.

It doesn't need sorted data, but it's slow at O(n).

📍Where It's Used
  • Small unsorted data
  • one-off lookups

03 Python Implementation

A clean, readable reference implementation of the core logic of Linear Search.

core_implementation.py
def linear_search(arr, target):
    for i in range(len(arr)):
        if arr[i] == target:
            return i
    return -1

04 Frequently Asked Questions

FAQ
What is Linear Search?+

The most basic search method: checks every element in order from the start of the array until it finds the target.

What is the time complexity of Linear Search?+

The time complexity of Linear Search is O(n). Follow the step-by-step visualization to see exactly why.

Where is Linear Search used?+

Small unsorted data, one-off lookups.

What's a simple analogy for Linear Search?+

Compares values one at a time from the front. The data need not be sorted, but the worst case looks at all of it.