| Complexity | Type | Operations | Visual |
|---|---|---|---|
| O(1) | Constant | 1 | |
| O(n) | Linear | 1000 | |
| O(n log n) | Linearithmic | 9.97K | |
| O(n²) | Quadratic | 1000.00K |
Common Algorithm Examples
What is Big O Calculator?
Big O notation quantifies how an algorithm's resource consumption — typically time or space — scales as the size of the input grows toward infinity. It captures the dominant growth rate while ignoring constant factors and lower-order terms, giving developers a language-agnostic way to compare algorithm efficiency. An O(n) algorithm doubles its runtime when the input doubles, while an O(n log n) algorithm grows slightly faster, and an O(n squared) algorithm quadruples its runtime for a doubling of input. Understanding these growth rates is essential for choosing the right algorithm before you invest in implementation.
How to Use
- Select an input size using the preset buttons (10 to 1 million) or type a custom value
- Choose which complexity classes to compare by clicking the toggle buttons
- The results table shows the exact number of operations each complexity requires at your chosen input size
- Visual bars use a logarithmic scale so you can compare orders of magnitude at a glance
- The estimated time panel converts operation counts into wall-clock time at 1 billion operations per second
- Match algorithms to their complexities using the common examples reference at the bottom
Why Use This Tool?
Tips & Best Practices
- O(n squared) algorithms work fine for small inputs but become impractical above 10,000 items
- At one million items, O(n squared) requires one trillion operations — that is minutes to hours of compute time
- O(log n) is nearly as fast as O(1) for any realistic input size because log base 2 of one billion is only about 30
- Always profile with your actual data size before optimizing — an O(n squared) algorithm may outperform O(n log n) for small n due to lower constant overhead
- Space complexity matters too — an algorithm that is O(n) in time but O(n squared) in memory can crash before it finishes
Frequently Asked Questions
Why does Big O ignore constant factors?
Big O describes the asymptotic growth rate as input size approaches infinity. Constants matter for small inputs, but as n grows, the dominant term overwhelms them. O(1000n) and O(n) both scale linearly, so both are written as O(n). The 1000x difference is a constant factor that depends on hardware, language, and implementation — not on the algorithm itself.
At what input size does O(n squared) become a problem?
For 1,000 items, O(n squared) equals 1 million operations — usually fast enough. At 100,000 items, it is 10 billion operations — noticeable delay. At 1 million items, it is 1 trillion operations — minutes to hours. If your data might grow beyond 10,000 items, prefer an O(n log n) algorithm like merge sort or heap sort.
Is O(log n) basically constant time?
Practically, yes. log base 2 of 1 billion is approximately 30, and log base 2 of 1 trillion is approximately 40. Even for astronomical inputs, O(log n) operations stay tiny. This is why binary search on a massive sorted array feels instant regardless of size.
When should I NOT optimize for Big O?
Do not optimize for Big O when your actual input size is small and bounded. An O(n squared) algorithm with low constant overhead can outperform an O(n log n) algorithm for n under a few hundred. Premature optimization adds complexity for no real benefit. Profile first, then optimize the bottleneck.
Is my data private when using this tool?
Yes. This is a purely client-side calculator with no network calls. No data is sent to any server, and no information about your calculations is stored or logged.
How do I determine my algorithm's Big O?
Count nested loops: one loop over the input is O(n), two nested loops are O(n squared), three nested are O(n cubed). Halving the search space each iteration (like binary search) gives O(log n). Sorting then processing is typically O(n log n). Recursive calls that branch into two or more subproblems often yield exponential or factorial complexity.
Real-world Examples
Choosing a sorting algorithm for a product catalog
An e-commerce site needs to sort 100,000 products. Bubble sort would need 10 billion operations, while merge sort needs only about 1.7 million.
n = 100,000 | Compare O(n log n) vs O(n squared)
O(n log n): ~1,700,000 operations (~1.7 ms) O(n squared): ~10,000,000,000 operations (~10 seconds)
Binary search vs linear search in a sorted array
Searching a sorted array of 1 million items: linear search checks each element, while binary search halves the range each step.
n = 1,000,000 | Compare O(n) vs O(log n)
O(n): 1,000,000 operations (~1 ms) O(log n): ~20 operations (~0.00002 ms)