# Time Complexity

Source: https://cca.twango.dev/AP-Computer-Science/time-complexity

# Time Complexity

Big O notation describes an asymptotic upper bound on how an algorithm's work grows with input size $n$. It does not measure an exact number of seconds.

| Growth | Notation |
| --- | --- |
| Constant | $O(1)$ |
| Logarithmic | $O(\log n)$ |
| Linear | $O(n)$ |
| Quadratic | $O(n^2)$ |
| Exponential | $O(2^n)$ |

## Binary search

Binary search repeatedly halves the remaining range in a sorted list. Its worst-case number of iterations grows on the order of $\log_2 n$.

> [!note] Review clarification
> The original expression $\log_2 n$ describes the growth rate, not the exact integer number of steps for every implementation and input. For example, a standard inclusive-bound search of a nonempty list takes at most $\lfloor\log_2 n\rfloor + 1$ iterations.

Related: [[arrays|Arrays]] · [[loops|Loops]] · [[recursion|Recursion]]
