# Linear Search

> Checking each item in turn until you find a match.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Sequential Search

## Think of it like

Think of it like looking for a sock. You open each drawer, one at a time.

## Definition

Linear search finds an item by checking each one in turn, from the start. It stops when it finds a match, or when it reaches the end. It works on any list, sorted or not. For a list of n items it can take up to n checks, so it is O(n). It is the right choice for short lists and lists you search only once.

## Example

Jack looks for 9 in the list 4, 7, 1, 9. Linear search checks four numbers and finds it at position 3.

## Example code

```python
>>> [4, 7, 1, 9].index(9)
3
```

index walks the list from the start until it finds 9.

## Why it matters

It is simple and always works. Knowing its cost tells you when to reach for something faster.

## Common mistake

Running a linear search inside a loop over the same big list. That quietly turns O(n) into O(n²).

## Three principles

- **One by one.** From the start.
- **Any list.** Sorted or not.
- **O(n).** Slow on big lists.

## Related terms

- [Binary Search](https://learn.benibix.com/term/development/binary-search)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)
- [Big O Notation](https://learn.benibix.com/term/development/big-o-notation)
- [Array](https://learn.benibix.com/term/development/array)
- [Best, Worst and Average Case](https://learn.benibix.com/term/development/best-worst-average-case)

## Told apart from

- [Linear Search vs Binary Search](https://learn.benibix.com/compare/linear-search-vs-binary-search): Linear search checks every item, one by one, and works on any list. Binary search needs a sorted list, but halves it each step, so a million items take about 20 checks.

---

Source: https://learn.benibix.com/term/development/linear-search
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
