⏱ 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++.
⏱
Paste code and click Analyze
Supports Python, JavaScript, Java, C++
📊 Big-O Reference
Hash lookup, array index
Binary search, BST
Linear scan, single loop
Merge sort, heap sort
Nested loops, bubble sort
Backtracking, subsets
All permutations
🧩 Pattern → Complexity
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²).