We Value Your Privacy

We use cookies to enhance your browsing experience and analyze site traffic. All calculations happen locally in your browser - we never see or store your data. Learn more in our Privacy Policy

/
/
CalculateYogi
  1. Home
  2. Technology
  3. Big-O Complexity Calculator
Technology

Big-O Complexity Calculator

Analyze your code's time and space complexity. Paste Python, JavaScript, Java, C++, C# or Go and see the loop-by-loop derivation behind the Big-O.

Example algorithms

Paste a complete function for the best reading. Comments and strings are ignored, so a loop written inside a string will not be counted.

Analysis options

Optional. Time a simple loop on the machine that will run this and divide its iterations by the seconds it took — we publish no figure for how fast a computer is. Leave it blank and the analysis is unchanged.

Complexity classes, slowest-growing first

The eight classes almost every algorithm falls into.

NotationNameGrowthPractical limit
O(1)ConstantNo growthUnbounded
O(log n)Logarithmic+1 step per doubling of nBillions
O(n)Linear2x input, 2x timeTens of millions
O(n log n)LinearithmicA little steeper than linearMillions
O(n²)Quadratic2x input, 4x timeTens of thousands
O(n³)Cubic2x input, 8x timeHundreds
O(2^n)Exponential+1 element, 2x timeAbout 30–40
O(n!)Factorial+1 element, (n+1)x timeAbout 10–12

Data structure operation costs

Average-case cost per operation, with the space the structure itself occupies.

StructureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
Linked listO(n)O(n)O(1)O(1)O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)
Hash tableN/AO(1)O(1)O(1)O(n)
Binary search treeO(log n)O(log n)O(log n)O(log n)O(n)
AVL treeO(log n)O(log n)O(log n)O(log n)O(n)
Red-black treeO(log n)O(log n)O(log n)O(log n)O(n)
B-treeO(log n)O(log n)O(log n)O(log n)O(n)
HeapN/AO(n)O(1)O(log n)O(n)

Sorting algorithm comparison

Best, average and worst-case time, the extra space required, and whether equal elements keep their original order.

AlgorithmBestAverageWorstSpaceStable
QuicksortO(n log n)O(n log n)O(n²)O(log n)No
Merge sortO(n log n)O(n log n)O(n log n)O(n)Yes
HeapsortO(n log n)O(n log n)O(n log n)O(1)No
TimsortO(n)O(n log n)O(n log n)O(n)Yes
Bubble sortO(n)O(n²)O(n²)O(1)Yes
Insertion sortO(n)O(n²)O(n²)O(1)Yes
Selection sortO(n²)O(n²)O(n²)O(1)No
Radix sortO(nk)O(nk)O(nk)O(n + k)Yes
Counting sortO(n + k)O(n + k)O(n + k)O(k)Yes
Bucket sortO(n + k)O(n + k)O(n²)O(n)Yes

This analyzer reads code structure — loop nesting, loop step form, recursion shape, known library costs and allocations. It cannot see data-dependent behaviour, library internals, or logic that changes the trip count at runtime. Treat the result as a well-evidenced reading of the code you pasted, and check the derivation against your own understanding.

Did this calculator solve your problem today?

Contributor

Reviewed by

Last updated: August 24, 2026
SupportI build these free tools with love, late nights, and way too much coffee. If this calculator helped you, a small donation would mean the world to me and help keep this site running. Thank you for your kindness!

Related Calculators

You might also find these calculators useful

Cyclomatic Complexity Calculator

Paste your code and get its cyclomatic complexity, function by function

Array Size Calculator

Array memory footprint, and how to read its length

Code Coverage Calculator

Coverage by criterion, checked against requirements we can cite

Lines of Code Calculator

Count SLOC, comments and blanks from pasted code, then estimate effort

Find the Big-O of your own code

Paste a function and this calculator reads its structure — how loops nest, how each loop advances, how a recursive call shrinks its argument, which library calls hide a scan — and reports both the time and the space complexity. Every conclusion is listed against the line that produced it, so you can check the reasoning rather than take a notation on trust. Nothing is uploaded: the analysis runs entirely in your browser.

What Big-O notation actually measures

Big-O describes how the work an algorithm does grows as its input grows, ignoring constant factors and lower-order terms. An O(n²) function is not necessarily slow — on ten elements it may well beat an O(n log n) one — but as n rises the growth rate decides the outcome, and no amount of micro-optimisation changes the class. Time complexity counts basic operations; space complexity counts memory. Both are reported here, because a solution that trades one for the other is only judged fairly when you can see both.

The definition

How to use the analyzer

1

2

3

4

5

When this is useful

Interview preparation

Write a solution, check the complexity you think it has against the one its structure actually implies, and see exactly which line makes it quadratic when the two disagree.

Code review

A function that scans a list inside a loop passes tests and fails in production. Pasting the diff's hot function gives a reviewable, line-referenced reason to ask for a set instead.

Teaching and learning

The derivation makes the abstract rules concrete: sequential blocks take the maximum, nested blocks multiply, and a halving step contributes a logarithm.

Choosing between two implementations

Analyze both and compare the notations and the operation counts at the input size you actually expect, rather than at the asymptote.

Why read the derivation, not just the answer

A notation with no working is unverifiable

Most online Big-O tools send your snippet to a language model and return a bare O(...) with no reasoning. When it is wrong — and on unusual code it will be — nothing on the page tells you so. Here each finding names the line it came from and what it multiplied the answer by.

The hidden costs are the ones that bite

A slice inside a loop, a repeated string concatenation, a membership test against a list rather than a set: each looks like one statement and each is a full scan. These are the most common causes of a function that is quietly quadratic, and they are listed explicitly.

Two inputs are not one input

Nested loops over two different collections are O(n × m), not O(n²). When the code has two dimensions the analysis names them separately and tells you which variable each one stands for.

Knowing what could not be determined is part of the answer

Data-dependent loops, pivot-based recursion and unfamiliar library calls are stated as limits rather than papered over with a confident guess.

Frequently asked questions

Count how many times each statement runs as a function of the input size. Sequential blocks take the maximum of their costs; nested blocks multiply. A loop that adds a fixed amount to its counter is linear; one that multiplies or divides it is logarithmic. A recursive function is solved by its recurrence: two calls on half the input plus linear work gives n log n, two calls on n − 1 gives 2^n. This calculator applies exactly those rules and shows each application against a line number.

Python, JavaScript and TypeScript, Java, C and C++, C# and Go. Detection is automatic, and you can override it. The analysis is structural rather than a full parse, so it also copes with an incomplete snippet — a loop body pasted without its enclosing function still reads correctly.

For the loop, recursion and library shapes it recognises, yes — and it shows its working so you can confirm. What it cannot see is behaviour that depends on the data: a loop that usually exits early, a hash table that degrades to a list on adversarial keys, a library call whose cost depends on an argument. Those are reported as limits, not folded silently into the answer.

Time complexity counts operations as the input grows; space complexity counts memory. They frequently trade against each other — memoising a recursive function turns exponential time into linear time by spending linear space. Reading only one of them hides the price of the other, which is why both are shown here.

Auxiliary space is the memory an algorithm allocates on top of the input it was handed. An in-place sort is O(1) auxiliary even though the array it sorts is n elements long, because it did not allocate that array. This is the convention used in interviews and in most textbooks.

Because the two loops iterate different collections. Their sizes are independent, so the cost is the product of two separate dimensions and collapsing it to n² would assert a relationship the code does not contain. The badges under the result show which variable each symbol stands for.

No. The analysis runs in your browser. Nothing is sent to a server, which is also why there is no wait for a response and no rate limit.

CalculateYogi

The most comprehensive calculator web app. Free, fast, and accurate calculators for everyone.

Calculator Categories

  • Math
  • Finance
  • Health
  • Conversion
  • Date & Time
  • Statistics
  • Science
  • Engineering
  • Business
  • Everyday
  • Construction
  • Education
  • Technology
  • Food & Cooking
  • Sports
  • Climate & Environment
  • Agriculture & Ecology
  • Social Media
  • Other

Company

  • About
  • Contact
  • Contributors

Legal

  • Privacy Policy
  • Terms of Service
  • Editorial Policy

© 2026 CalculateYogi. All rights reserved.

Sitemap

Made with by the AppsYogi team