---
title: "Linear Search"
description: "Looking for a value by checking items one after another until it is found or the collection runs out, and counting the checks that takes in the best and worst case."
canonical: https://lightmysky.com/learn/computing/linear-search-mt_32LwZIhSiB
source: https://lightmysky.com/learn/computing/linear-search-mt_32LwZIhSiB.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Linear Search

Looking for a value by checking items one after another until it is found or the collection runs out, and counting the checks that takes in the best and worst case.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/linear-search-mt_32LwZIhSiB

## Ready when they can

- Write a loop that reports the position of a value, or reports that it is absent
- Say how many comparisons the worst case needs for a list of a given length
- Explain why this search works on data in any order

## Lesson: Start at the front, stop at the match

Imagine scanning a class list for one name. Linear search does the same: it checks items one after another from the front, asking if each one equals the target. It stops with the seat number on a match, or reports absent at the end.

**Example.** Take searchList with 3, 37, 45, 57, 93 and 120, hunting 45. Checks answer no, no, then yes at the third item, so it hands back seat 3. Hunting 99 would check all six and hand back -1.

The worst case checks every item, so twice the list means twice the worst time. On a nonempty list, best case finds the target first, and average lands mid-list. For 30 names the hunt may need 30 checks.

**Tip.** No sorting, no setup: on jumbled data, short lists or one-off hunts, the simple scan wins. Pay for sorting only when many searches follow.

**Recap.** Check from the front until match or end, count the checks, and expect the worst to grow with the list.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Tracing a Program by Hand](https://lightmysky.com/learn/computing/tracing-a-program-by-hand-mt__rsnZ5Goow)
- [Traversing a List to Build a Result](https://lightmysky.com/learn/computing/traversing-a-list-to-build-a-result-mt_lusbjHFt95)

## Opens up

- [Binary Search on Sorted Data](https://lightmysky.com/learn/computing/binary-search-on-sorted-data-mt_3avV-VasFZ)
- [Counting Operations to Compare Algorithms](https://lightmysky.com/learn/computing/counting-operations-to-compare-algorithms-mt_JkN961niFG)
