ToolSphere

Big-O Complexity Calculator

Computer science

Compare Big-O growth at any input size with exact integers, base-2 logarithms, a log-scale chart and examples showing how algorithm costs change.

Modeled work at n = 16

Algorithm B uses less work

A: 20 × n = 320

B: 1 × n² = 256

Fewer modeled operations; actual speed depends on implementation and hardware.

Growth values at n = 16

Unscaled functions. Integer values are exact; ≈ marks rounded logarithms. Expand long integers to read every digit.

1
1
log₂ n
4
n
16
n log₂ n
64
n²
256
n³
4096
2ⁿ
65536
n!
20922789888000

Growth on a log scale

x: input size, 1 to 16. y: log₁₀(work), from 0 to 13.3. Equal vertical steps multiply work. Zero log₂(1) is omitted. Curves are sampled; multipliers above are excluded.

  • 1
  • log₂ n
  • n
  • n log₂ n
  • n²
  • n³
  • 2ⁿ
  • n!

Compare explicit growth functions, not source code or arbitrary recurrences. Solve a recurrence with the master theorem calculator, or trace actual passes in the sorting tool.

On this browser only

Give feedback

Did this tool help?

Tell us what worked, what didn’t, or what you’d like next.

Opens Google Forms in a new tab with this tool’s name filled in. No sign-in or email required. Feedback is optional.

How to use Big-O Complexity Calculator

  1. 1Enter a whole-number input size from 1 to 1,000.
  2. 2Choose growth functions and positive integer multipliers for algorithms A and B.
  3. 3Read the modeled-work comparison above the fields, then inspect all eight unscaled values.
  4. 4Use the log-scale chart and loaded examples to compare growth; benchmark actual code separately.

About Big-O Complexity Calculator

Compare growth before choosing an algorithm

Enter an input size to evaluate constant, logarithmic, linear, linearithmic, quadratic, cubic, exponential and factorial growth. This Big-O complexity calculator compares explicit mathematical models. It does not inspect source code, count instructions in a program or prove a complexity bound. Use it alongside your Intro to Algorithms homework to see how a growth function changes as an input gets larger. The loaded comparison puts two concrete operation models side by side before the input fields, so you can start with an answer and then change the assumptions.

The input size must be a whole number from 1 through 1,000. Think of n as the number of records, array elements or vertices relevant to your model. Keep that meaning consistent between algorithms. An algorithm measured against the number of edges cannot be compared fairly with one measured against the number of vertices unless you first relate those quantities. Blank, fractional and out-of-range inputs clear the results instead of silently substituting an example.

What the eight functions mean

The constant function represents work that stays fixed in this model. The logarithmic function uses base two, a natural choice for repeated halving. Linear growth scales directly with input size, while n log₂ n combines a linear amount of work with logarithmically many levels. Quadratic and cubic functions describe stronger polynomial growth. The exponential function doubles whenever n increases by one. Factorial multiplies all positive integers through n and appears when considering permutations without pruning.

These are representative functions, not automatic classifications of every algorithm that uses a particular technique. A nested loop may stop early or iterate over different ranges. A recursive routine may make unequal subproblems. Write a recurrence or count the actual iterations before selecting a model. The master theorem calculator helps with supported divide-and-conquer recurrences. Bring the resulting growth function here to compare its scale with other functions.

Worked example: which algorithm is faster?

The loaded example sets n to 16, Algorithm A to 20n and Algorithm B to n². Running the calculation library gives 320 modeled operations for A and 256 for B. B uses less work at this input size even though its quadratic model grows faster eventually. Choose the larger-input example to set n to 32. The same models now give 640 for A and 1,024 for B, so A uses less work. The conclusion changes because the constant multiplier matters for a finite input.

You can edit either multiplier to represent an assumed cost per unit of growth. Multipliers are positive whole numbers through 1,000,000. They are illustrative operation costs, not measurements supplied by this site. If both models return the same value, the answer explicitly reports a tie. For these particular models, n equal to 20 gives 400 operations on each side. Use nearby input sizes to investigate a crossover, then check the algebra in your homework solution.

Compare sorting models

Choose the sorting example to compare n log₂ n with n² at n equal to 64. The library returns 384 and 4,096 respectively, with both multipliers set to one. These are growth-function values, not the exact comparison counts of merge sort or insertion sort. Their actual counts depend on implementation details and input order. Open the sorting algorithm visualizer to inspect concrete passes, swaps and comparisons on an array instead of assuming that a growth expression is a complete execution trace.

Exact values and rounded logarithms

The unscaled list evaluates all eight functions at your chosen n. Integer calculations use BigInt, preserving digits beyond ordinary floating-point integer precision. At n equal to 64, the exact value of 2ⁿ is 18446744073709551616. Long answers can be expanded to reveal every digit without filling the initial screen with a factorial. The list excludes the two comparison multipliers so you can distinguish a base function from a scaled algorithm model.

When a base-two logarithm is an integer, its value and the corresponding n log₂ n value are exact integers too. Otherwise the tool preserves an exact symbolic expression and labels the decimal with an approximation sign. At n equal to 10, log₂(10) is approximately 3.3219281 and 10 × log₂(10) is approximately 33.219281. Those decimals are rounded for display; they are not exact rational results.

Read the logarithmic chart

The chart samples input sizes from one through your chosen n. Its vertical axis shows log₁₀ of each function value, allowing factorial and linear growth to share a plot. Equal vertical distances represent multiplicative changes in work. Dashed line patterns match the legend. Values of zero cannot appear on a logarithmic axis, so log₂(1) and its linearithmic counterpart are omitted there; the exact-value list still shows them.

Big-O describes an asymptotic upper bound, whereas this page evaluates named functions at finite inputs. It cannot establish measured running time, memory consumption or a tight bound by itself. Use a benchmark for actual speed and a proof for a complexity claim. The chart helps build intuition after you have chosen a valid model.

Guides and tutorials

Frequently asked questions

Does this calculator find Big-O from code?

No. It evaluates eight named growth functions and two scaled models. You must derive the function from your algorithm first.

Which logarithm base is used?

The functions use log base two. The chart uses log base ten for its vertical axis. Changing a fixed log base only changes a constant factor asymptotically.

Are large factorials exact?

Yes. Integer powers and factorials use BigInt through the supported maximum n of 1,000. Expand a long result to see every digit.

Why are some logarithms approximate?

Base-two logarithms are generally nonintegers. The tool keeps the exact symbolic expression and marks the rounded decimal with ≈. Powers of two have integer logarithms.

Which algorithm is faster at a particular n?

Choose two functions and their assumed multipliers. The result identifies the model with less work at that n. Actual speed also depends on hardware, input and implementation.

Can a quadratic algorithm win for small inputs?

Yes. In the loaded example, n² is 256 at n = 16, while 20n is 320. At n = 32 the values become 1,024 and 640, reversing the result.

Does the chart include my multipliers?

No. The chart and eight-value list show unscaled functions. The answer above the form applies the separate multipliers to algorithms A and B.

Why is zero missing from the log-scale chart?

The logarithm of zero is undefined. The logarithmic and linearithmic functions equal zero at n = 1, so those chart points are omitted. Their values remain in the list.

Can I solve a recurrence here?

Use the linked master theorem tool for supported divide-and-conquer recurrences. This page compares growth functions after you derive them; it is not an arbitrary recurrence solver.

Are the sorting values exact comparison counts?

No. A function such as n log₂ n is a mathematical model. Use the linked sorting visualizer to see comparison counts for an actual algorithm and input array.

Have a suggestion for Big-O Complexity Calculator?Share your feedback ↗