# Best, Worst and Average Case

> How fast code runs on the best input, the worst one and a normal one.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Worst Case, Best Case, Average Case, Worst-Case Complexity

## Think of it like

It is like looking for your shoes. Some days they are by the door, some days they are lost.

## Definition

The same algorithm can be fast or slow, depending on the input. The best case is the luckiest input. The worst case is the unluckiest one. The average case is what to expect over many normal inputs. Big O is most often given for the worst case, because that is the promise you can count on.

## Example

A linear search over 1,000 names finds the first name in 1 step. It needs 1,000 steps for the last one or a missing one.

## Why it matters

A sort that is quick on most data can still freeze on a bad input. The worst case tells you how bad it can get.

## Common mistake

Quoting the best case as if it were normal. Plan for the worst case unless you know your data well.

## Three principles

- **Best case.** The luckiest possible input.
- **Worst case.** The slowest it can ever be.
- **Average case.** What to expect most days.

## Related terms

- [Big O Notation](https://learn.benibix.com/term/development/big-o-notation)
- [Time Complexity](https://learn.benibix.com/term/development/time-complexity)
- [Linear Search](https://learn.benibix.com/term/development/linear-search)
- [Quicksort](https://learn.benibix.com/term/development/quicksort)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)

![A row of eight boxes searched from the left. Three arrows mark the three cases. Best case: the item is in box 1, found after 1 look. Average case: it is near the middle, found after about 4 looks. Worst case: it is in the last box or missing, so all 8 are checked.](https://learn.benibix.com/diagrams/dev7-best-worst-case.svg)

---

Source: https://learn.benibix.com/term/development/best-worst-average-case
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.
