Labs

Big-O growth

Move n and watch O(n²) blow past a one-second budget while O(n log n) barely moves.

CPH limits (~1 s)
  • O(1)1 step · 10 ns
  • O(log n)17 steps · 166 ns
  • O(n)100k steps · 1 ms
  • O(n log n)1.66M steps · 16.6 ms
  • O(n²)10B steps · 1.67 min
  • O(n³)1.0×10¹⁵ steps · 116 days
  • O(2ⁿ)1.0×10³⁰¹⁰³ steps · 3.2×10³⁰⁰⁸⁷ years
CPH rule for this nO(n log n)or O(n)
log₂ n≈ 17a log factor is cheap
Slowest that fits 1 sO(n log n)16.6 ms at 10⁸ ops/s
Clock—
  • O(1)
  • O(log n)
  • O(n)
  • O(n log n)
  • O(n²)
  • O(n³)
  • O(2ⁿ)

At n = 100k, O(n log n) still fits in ~1 s, but O(n²) already takes 1.67 min. Read the limit on n first: it tells you which algorithm the problem expects.

How it's calculated · assumptions

time ≈ steps ÷ 10⁸ simple ops/s · 1 s budget ≈ 10⁸ steps · vertical line = 1 s

Assumption: 10⁸ simple operations per second, the low end of the concept's "some hundreds of millions"; orange rows (1–10 s) are borderline, since a faster machine or a smaller constant can make them fit. Constants are dropped and log means log₂. Budget table: Laaksonen, Competitive Programmer's Handbook.