Skip to main content

⏱ Big O Complexity Calculator & Time Complexity Analyzer

Paste your code below into our free time complexity calculator to get an instant Big-O complexity breakdown — time complexity, space complexity, loop analysis, and asymptotic bounds. Supports Python, JavaScript, Java, and C++.

✓ 100% Client-Side ✓ No Login Required ⚡ Instant Results
| Examples:

⏱

Paste code and click Analyze

Supports Python, JavaScript, Java, C++

📊 Big-O Reference

O(1) Constant

Hash lookup, array index

O(log n) Logarithmic

Binary search, BST

O(n) Linear

Linear scan, single loop

O(n log n) Linearithmic

Merge sort, heap sort

O(n²) Quadratic

Nested loops, bubble sort

O(2ⁿ) Exponential

Backtracking, subsets

O(n!) Factorial

All permutations

🧩 Pattern → Complexity

Single loop O(n)
Nested loops (×2) O(n²)
Binary search O(log n)
HashMap usage O(n)
Recursion (linear) O(n)
Recursion (tree) O(2ⁿ)
Merge sort O(n log n)
BFS / DFS O(V+E)
2D DP table O(n×m)

Frequently Asked Questions

What is time complexity? +

Time complexity describes how the runtime of an algorithm scales with input size n. Common complexities are O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic, and O(2ⁿ) exponential. For interviews, always analyze your solution before coding.

What is the difference between best, average, and worst-case complexity? +

Best case is the fastest scenario (e.g., target found at index 0). Average case is the expected runtime for random inputs. Worst case (Big-O) is the upper bound — what interviewers typically ask about. Quicksort has O(n log n) average but O(n²) worst case.

How is space complexity calculated? +

Space complexity counts all memory your algorithm uses relative to input size. This includes: variables and data structures you create (auxiliary space), and the call stack for recursive functions. In-place algorithms have O(1) space. HashMap-based solutions usually O(n) space.

What does amortized complexity mean? +

Amortized complexity averages the cost of operations over a sequence. For example, appending to a dynamic array is O(1) amortized even though resizing is O(n) — because resizing is rare. Python lists and Java ArrayLists use this.

How do I analyze nested loops? +

Multiply the complexities of nested loops. One loop O(n) nested inside another O(n) = O(n²). If the inner loop size depends on the outer variable (like j goes from 0 to i), it's still O(n²) but with a coefficient of 0.5 — drop constants, keep O(n²).

Buy me a coffee
Daily Practice
0/0