n² at n = 1,000
- Input size n
- 1000
- Operations per second
- 1e9
- Your algorithm
- O(n²)
- Operations
- 1,000,000
- Running time in seconds
- 0.001 s
- Running time
- 1 ms
Checked against: Independent calculation
Operation counts and running times for O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ) and O(n!) at your input size, on a log-scale chart.
By AdminDrafted with AI writing toolsUpdated Checked examples: 6
At n = 1,000, the O(n log n) growth model gives about 9,966 operations, which takes 9.966 µs at 1,000,000,000 operations per second. Curves are clipped at the top of the chart; this does not by itself identify a complexity class.
| Class | Operations | log₁₀ | Time |
|---|---|---|---|
| O(1) | 1 | 0 | 1 ns |
| O(log n) | 9.9658 | 0.999 | 9.966 ns |
| O(n) | 1,000 | 3 | 1 µs |
| O(n log n) | 9,965.78 | 3.999 | 9.966 µs |
| O(n²) | 1,000,000 | 6 | 1 ms |
| O(n³) | 1,000,000,000 | 9 | 1 s |
| O(2ⁿ) | 1.07151 × 10³⁰¹ | 301.03 | 3.395 × 10²⁸⁴ years |
| O(n!) | 4.02387 × 10²⁵⁶⁷ | 2,567.605 | 1.275 × 10²⁵⁵¹ years |
Logarithms are base 2 (halving or binary splitting); another base changes the count by a constant factor only.
9.966 µs
Big-O notation describes how an algorithm's work grows with the input size n, leaving out constant factors. The calculator evaluates each growth function f(n), namely 1, log2 n, n, n log2 n, n², n³, 2ⁿ and n!, at your n, then divides by the number of simple operations the machine does per second to estimate the running time.
It helps judge whether an approach will finish in time before you write it. At the default n = 1,000 and 10^9 operations per second, an O(n log n) sort does about 9,966 operations and takes about 10 µs, and O(n²) takes 1 ms, while O(2ⁿ) at only n = 100 would need 4.0 × 10^13 years.
In the formula, r is operations per second. Read the times as orders of magnitude: real code adds constant factors, cache effects and lower-order terms that Big-O leaves out.
Evaluate the growth function at your input size, then divide by the number of simple operations the machine does per second: t = f(n) ÷ r. At n = 1,000 and 10⁹ operations per second, n log₂ n is about 9,966 operations, roughly 10 µs, and n² is 1,000,000 operations, or 1 ms. Use it to compare approaches before writing code.
NIST's definition says f(n) is O(g(n)) when some constant multiple of g(n) bounds f(n) from above for every n past some point. It describes growth, so constant factors and lower-order terms drop out.
So n² + 1,000n is O(n²). At n = 1,000 the extra term doubles the work, 2 million operations instead of 1 million, but at n = 1,000,000 it adds only 0.1%.
A bound also belongs to a case. Quicksort is O(n²) in the worst case and O(n log n) on average, and a hash-table lookup is O(1) on average but O(n) in the worst case.
At 10⁹ operations per second:
Doubling n adds one operation to log₂ n, doubles n, slightly more than doubles n log₂ n, multiplies n² by 4 and n³ by 8, and squares 2ⁿ.
At 10⁹ simple operations per second, one second of work covers:
These limits explain why code that is instant on test data can stall in production. An O(n²) step that takes 1 ms on 1,000 items needs 10¹² operations, about 16.7 minutes, on 1,000,000.
| Scenario | Model operations | Model time |
|---|---|---|
| Default | 9965.78 | 9.966 µs |
| Quadratic thousand | 1.00000E+6 | 1 ms |
| Exponential hundred | 1.26765E+30 | 4.017 × 10¹³ years |
| Twenty factorial | 2.43290E+18 | 77.1 years |
| One logarithm | 0 | 0 s |
Every row assumes 10⁹ operations per second. Default is n log₂ n and Quadratic thousand is n², both at n = 1,000. The other rows are 2ⁿ at n = 100, 20! and log₂ 1, which is zero. E+30 means × 10³⁰.
The 10⁹ figure fits simple CPU steps, such as comparisons in a tight loop. If one operation is a database query or a network request, measure instead: a loop that finishes 1 million operations in 2 seconds runs at 500,000 per second.
A faster machine divides every time by the same factor and leaves the operation counts alone. Ten times the speed barely helps exponential work: at 10¹⁰ operations per second, 2ⁿ still stops at n = 33 within one second.
sorted(), uses insertion sort on short runs for this reason.When the bottleneck is moving data, the bandwidth calculator estimates transfer time.
Checked against: Independent calculation
Checked against: Independent calculation
Checked against: Independent calculation
Checked against: Independent calculation
At n = 1,000, n log2 n is about 9,966 while n² is 1,000,000, roughly 100 times more; at n = 1 million the gap is about 50,000 times (2 × 10^7 against 10^12). That is why merge sort and heapsort, which are O(n log n), beat insertion sort and bubble sort, which are O(n²) in the worst case, on anything but small inputs.
O(log n) means the work grows with the logarithm of the input size, usually because each step halves what is left, as in binary search. Doubling n adds only one step: a sorted list of 1,000 items needs about 10 comparisons (log2 1,000 ≈ 9.97), and 1 million items about 20. The base of the logarithm changes only a constant factor, so the notation leaves it out.
Their work multiplies with each extra item. 2ⁿ doubles whenever n grows by 1, so at n = 100 it is about 1.27 × 10^30 operations, or 4.0 × 10^13 years at 10^9 per second, roughly 2,900 times the age of the universe. n! grows faster still: 20! is already 2.43 × 10^18, about 77 years of work. Brute-force searches over all subsets or orderings fall into these classes.
No. Big-O bounds how work grows as n increases and drops constant factors and lower-order terms, so 3n² + 100n and n²/2 are both O(n²). Two O(n) algorithms can differ severalfold in speed, and for small n an O(n²) method can beat an O(n log n) one. Use the times here as orders of magnitude, then measure real code with a profiler.
Big-O is an asymptotic upper bound, Big-Omega (Ω) a lower bound, and Big-Theta (Θ) both at once, a tight bound. Merge sort is Θ(n log n) on every input, while insertion sort is O(n²) in the worst case and takes only n − 1 comparisons on already sorted input. Knuth set out these definitions in SIGACT News in 1976, and CLRS chapter 3 follows them.
This calculator includes 6 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.