How does your code behave as data grows? From O(1) always instant to O(n!) completely unusable — see all 7 complexities live across Array, Linked List, Stack, Queue, Tree & HashMap!
Click any complexity above to learn how it behaves as data grows from 10 to 1,000,000 items.
Click any operation button to animate it. The speedometer needle jumps to its complexity — so you always know why it’s fast or slow.
| Complexity | n=10 | n=100 | n=1,000 | n=10,000 | n=1M | Speed | Where in DS? |
|---|
O(n²) on 1M items = 1 trillion operations. At 1B ops/sec = 16 minutes. O(n) = 1 millisecond. Same data, same machine — 960,000× faster just by choosing the right algorithm!
BST search & binary search halve the problem each step. 1 billion sorted items needs only 30 steps to find any value. Each level of the tree eliminates half the remaining nodes!
These three never loop through data. Stack/Queue just update a pointer. HashMap uses a hash function to jump directly to the bucket. 10 items or 10 billion — always 1 step!
Naive Fibonacci: fib(n) calls fib(n-1) AND fib(n-2) — so work doubles each level. fib(50) triggers 250 ≈ 1 quadrillion calls! Fix: memoization or dynamic programming turns it O(n).
The Travelling Salesman brute-force: try every route permutation. 10 cities = 3.6 million routes (slow but ok). 20 cities = 2.4 quintillion routes — at 1B/sec that's 77 years. Heuristics are the only escape.
Best → Worst: O(1) → O(log n) → O(n) → O(n log n) → O(n²) → O(2ⁿ) → O(n!). The goal is always to push your algorithm as far LEFT as possible.