Compare growth rates, study curated best/average/worst-case complexity, and see real operation counts measured from instrumented implementations — with every limitation stated clearly.
Exact complexity cannot be determined just by running code. This page separates three different kinds of evidence:
Theoretical number of basic operations f(n) for each complexity class. Adjust n to see how quickly they diverge.
| Class | Name | Operations at n = 16 | at 2n = 32 | Typical example |
|---|---|---|---|---|
| O(1) | Constant | 1 | 1 | Array index access, stack push/pop |
| O(log n) | Logarithmic | 4 | 5 | Binary search |
| O(n) | Linear | 16 | 32 | Linear search, BFS/DFS (V + E) |
| O(n log n) | Linearithmic | 64 | 160 | Merge sort, heap sort |
| O(n²) | Quadratic | 256 | 1,024 | Bubble, selection, insertion sort |
| O(2ⁿ) | Exponential | 66K | 4.3B | Naive recursive Fibonacci, all subsets |
| O(n!) | Factorial | 20.9T | 2.6e35 | All permutations, brute-force TSP |
Curated theory for the selected algorithm, compared with operation counts measured from its instrumented implementation.
Time: In the worst case (reverse-sorted input) pass i makes n−1−i comparisons, giving (n−1)+(n−2)+…+1 = n(n−1)/2 comparisons → O(n²). With the swapped flag, an already-sorted array finishes after one pass of n−1 comparisons → O(n) best case.
Space: Sorting happens in place by swapping inside the same array. Only a few index variables (i, j, swapped) are used, so auxiliary space is O(1). The input array itself occupies O(n).
Counts come from the instrumented implementation (comparisons) at n = 8, 16, 32, 64, 128, 256. The dashed line is the theoretical growth function scaled to the largest measurement — a visual guide, not a proof.
Visualize Bubble SortPaste code to get a rough estimate from its structure. Always verify by reasoning about the loop bounds yourself.
O(n²)
Limitation: the analyzer only sees code structure. It cannot tell that a loop runs a constant number of times, that a recursion is memoised effectively, or what a library call costs internally.