Skip to content
UPEEC

Big-O Notation

Describe how an algorithm's time or memory grows as the input size grows.

Easy
Comments 0

Big-O ignores constants and keeps the dominant term:

Big-ONameExample
O(1)O(1)constantarray index, hash lookup
O(log⁡n)O(\log n)logarithmicbinary search
O(n)O(n)linearscanning a list
O(nlog⁡n)O(n \log n)linearithmicmerge sort
O(n2)O(n^2)quadraticnested loops, bubble sort
O(2n)O(2^n)exponentialbrute-force subsets

For n=106n = 10^6, O(nlog⁡n)O(n \log n) is about 2×1072 \times 10^7 steps, while O(n2)O(n^2) is 101210^{12} — the difference between milliseconds and hours.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.