⚡ Algorithm Analysis • Big O Notation

Big O — The Algorithm Speedometer

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!

☠️ O(n!) Worst
💥 O(2ⁿ)
🐢 O(n²)
O(n log n)
O(n) Linear
O(log n) Fast
🚀 O(1) Fastest
⚡ Rev the Algorithm Engine
Click any button to rev the engine!
Select a complexity

Click any complexity above to learn how it behaves as data grows from 10 to 1,000,000 items.

n = 10Any algorithm fine
n = 1,000,000Choice is critical!
COMPARISON FOR n = 100 (lower bar = faster)
⚡ Real-Time Complexity Race — drag n and watch!
Drag the slider and see how each complexity scales live. O(n²) explodes while O(1) stays perfectly flat!
n =
50
💡 Tip: At n=20 — O(1)=1, O(n)=20, O(n²)=400, O(2ⁿ)=1,048,576, O(n!)=2.4 quintillion!
Bar width = log₂ scale. ∞ = number exceeds JS limit. Drag slowly to see the explosion!
Deep Dive — Every Data Structure

Big O in Action — Click to Animate!

Click any operation button to animate it. The speedometer needle jumps to its complexity — so you always know why it’s fast or slow.

📋
Array
index-based · contiguous memory
O(1)Access / Append
O(n)Insert / Delete / Search
👇 Click an operation to animate
🔗
Linked List
pointer-based · dynamic nodes
O(1)Add/Del Head
O(n)Tail / Search / Access
👇 Click an operation to animate
📚
Stack
LIFO · all operations O(1) ✅
O(1)Push
O(1)Pop & Peek
👇 Click an operation to animate
🎯
Queue
FIFO · all operations O(1) ✅
O(1)Enqueue
O(1)Dequeue
👇 Click an operation to animate
🌳
BST / Tree
sorted hierarchy · halves each step
O(log n)Search/Insert
O(n)Traversal
👇 Click to see binary search path
📜
HashMap
key→value · all ops O(1) ✅
O(1)get(key)
O(1)set / delete
👇 Click a key to see O(1) lookup
📈 Operations Count as n Grows
Click any row to move the speedometer needle. O(2ⁿ) with n=100 = more operations than atoms in the observable universe! ∞ = number exceeds JavaScript's limit.
Complexityn=10n=100n=1,000n=10,000n=1MSpeedWhere in DS?
💡

Why O notation matters?

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!

Real impact
🔍

O(log n) — The Halving Trick

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!

BST & Binary Search

Stack, Queue & HashMap — All O(1)

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!

Always instant
💥

O(2ⁿ) — Doubles Every 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).

Avoid for n > 20
☠️

O(n!) — Factorial Death

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.

Only for n ≤ 10
🏆

The Golden Ranking

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.

Design principle