Enter a, b and k for T(n) = aT(n/b) + n to the power k to get the case and the Theta bound, with log base b of a shown to four decimals.

Master Theorem Calculator

Type in a recurrence, get its case and its Theta bound — merge sort, Karatsuba, Strassen and your homework recurrence alike.

Free to use Case identified log_b(a) shown Classic algorithms table

Enter your values

Fill in the fields below — the result appears with every step shown.

Shown on the printed, PDF and PNG copies of your result. Leave blank to stay anonymous.

Enter a valid value for a — subproblems per level.

Number of recursive subproblems, a ≥ 1.

Enter a valid value for b — size divisor.

Each subproblem is size n/b, b > 1.

Enter a valid value for k — exponent of the combine work.

Combine step costs Theta(n^k); use 0 for constant work.

Local browser calculation

Review your inputs and the tool’s supported scope before using the result.

Calculator loading… If this message stays, this view is not running the calculator's script — open this file in a full browser tab, then press Calculate.

Your result will appear here

Enter your values above, then press Calculate — or press Enter in any field.
TinyExe Master Theorem Calculator tinyexe.comFree online calculators

TinyExe · Master Theorem Result

Calculated locally in your browser

Calculated on
—

–
—

Name

—

a — subproblems per level

—

b — size divisor

—

k — exponent of the combine work

—

How this was calculated

    What to do next

      TinyExe · tinyexe.com — Runs 100% in your browser — your numbers never leave this tab; nothing is uploaded or stored.

      TinyExe PDF & PNG exports carry the TinyExe logo and tinyexe.com header & footer.

      Runs 100% in your browser — your numbers never leave this tab; nothing is uploaded or stored.

      Embed this tool

      Add this Master Theorem Calculator to your own page — copy the code below and paste it where you want the tool to appear.

      The embed loads the live calculator in a frame, so it stays up to date automatically. Choose a width, check the code, then copy it. When you publish on WordPress, keep the src pointing at your live tool URL.

      Works in WordPress (Custom HTML block), HTML pages, and most site builders.

      The short answer

      The master theorem solves T of n equals a T of n over b plus n to the k by comparing log base b of a with k. Merge sort has a equals 2, b equals 2, k equals 1, so log is 1, the balanced case, giving Theta of n log n.

      • Three cases: recursion dominates, balanced (extra log factor), or combine work dominates
      • log_b(a) is the leaf-growth exponent of the recursion tree
      • This tool covers polynomial combine work Theta(n^k)

      Classic recurrences solved

      Reference values for this calculator.

      Recurrencea, b, kResult
      Merge sort2, 2, 1Theta(n log n)
      Binary search1, 2, 0Theta(log n)
      Karatsuba multiplication3, 2, 1Theta(n^1.585)
      Strassen multiplication7, 2, 2Theta(n^2.807)
      Plain divide, heavy merge2, 2, 2Theta(n^2)

      The formula

      The exact formula this calculator uses — every variable in it is explained in the card below.

      The formula

      For T(n) = aT(n/b) + Theta(n^k): compare c = log_b(a) with k — c > k: Theta(n^c); c = k: Theta(n^k log n); c < k: Theta(n^k). (Regularity condition assumed for Case 3.)

      Ideas enhancement: names the case, not just the bound, and reports log_b(a) to four decimals so near-ties (like a=2, b=2, k=1) are visibly exact Case 2 rather than a coin flip.

      Worked examples

      Worked examples with the full working shown — try them in the calculator to check.

      Example 1

      Merge sort

      a=2, b=2, k=1

      CalculationSteps
      log_2(2) = 1 = k, so Case 2 applies: T(n) = Theta(n^1 log n).T(n) = Theta(n log n), dominant exponent 1.

      Result

      Example 2

      Recursion dominates

      a=4, b=2, k=1

      CalculationSteps
      log_2(4) = 2 > 1 = k, so Case 1: T(n) = Theta(n^2).T(n) = Theta(n^2), dominant exponent 2.

      Result

      Example 3

      Combine work dominates

      a=2, b=2, k=2

      CalculationSteps
      log_2(2) = 1 < 2 = k, so Case 3: T(n) = Theta(n^2).T(n) = Theta(n^2), dominant exponent 2 — same bound as Case 1 example, different reason.

      Result

      How to use this calculator

      Step 1

      Read a, b and k off your recurrence T(n) = aT(n/b) + Theta(n^k).

      Step 2

      Enter a (subproblems), b (size divisor) and k (combine-work exponent).

      Step 3

      The calculator computes log_b(a) and compares it with k.

      Step 4

      Read the case and the Theta bound.

      Step 5

      Sanity-check against a known algorithm in the table below.

      In short: The master theorem is a method for deriving the asymptotic running time of divide-and-conquer recurrences T(n) = aT(n/b) + f(n).

      Frequently asked questions

      What is the master theorem?

      It solves divide-and-conquer recurrences of the form T(n) = aT(n/b) + f(n) by comparing the work done in the recursive calls, governed by log_b(a), with the work done combining results, governed by f(n). Whichever grows faster sets the total cost, unless they tie, which adds a log factor.

      Why does Case 2 add a log n?

      When recursion and combine work balance at every level, each of the log_b(n) levels contributes the same amount, so the per-level cost is multiplied by the number of levels — hence Theta(n^k log n), as in merge sort.

      What is the regularity condition in Case 3?

      Case 3 also needs a·f(n/b) ≤ c·f(n) for some c < 1 and large n, so the combine work genuinely shrinks down the tree. For polynomial f(n) = n^k this holds automatically, which is the form this calculator accepts.

      My combine work is n log n, not n^k — can I still use this?

      Not directly. This tool handles polynomial combine work Theta(n^k), the form in most coursework. Polylog factors need the extended Akra-Bazzi method or a recursion-tree argument.

      What does log_b(a) mean intuitively?

      It is the growth rate of the number of leaves in the recursion tree. If it exceeds k, the leaves dominate and the answer is Theta(n^{log_b a}); Strassen's log_2(7) ≈ 2.807 is the famous example.

      About this calculator

      A master theorem calculator solves divide-and-conquer recurrences T(n) = aT(n/b) + Θ(n^k) — the shape shared by merge sort, binary search, Karatsuba and Strassen — by identifying which of the theorem's three cases the recurrence falls into and returning the tight Θ bound.

      Picture the recursion tree. It has log_b(n) levels; the leaves number n^{log_b(a)}, and the combine work at the top is n^k. The master theorem is just the contest between those two forces. If the leaves grow faster (log_b(a) > k), almost all the work sits at the bottom and T(n) = Θ(n^{log_b a}) — Case 1, the home of Strassen's algorithm.

      If the two balance exactly (log_b(a) = k), every level costs the same and the total picks up a factor for the number of levels: T(n) = Θ(n^k log n), Case 2. Merge sort lives here. If the top-level combine work grows fastest (log_b(a) < k), the root dominates and T(n) = Θ(n^k), Case 3, provided the regularity condition holds — which it always does for pure polynomials.

      The commonest student errors are misreading k: merge sort's combine step is linear, so k = 1, not 'log'; binary search discards half and does constant work, so a = 1, k = 0 and log_2(1) = 0 gives Case 2 and Θ(log n). A second error is applying the theorem to recurrences it does not cover, such as T(n) = T(n−1) + n.

      Use it in algorithms coursework to check a hand derivation, when analysing your own recursive code before optimising it, and when comparing two algorithms whose recurrences differ only in a, b or k — the comparison instantly shows whether cutting subproblems or cutting combine work helps more.

      How to calculate it yourself

      Step 1

      Write the recurrence as T(n) = aT(n/b) + Θ(n^k), reading a, b and k directly.

      Step 2

      Compute c = log_b(a) = ln a / ln b.

      Step 3

      If c > k, answer Θ(n^c). If c = k, answer Θ(n^k log n). If c < k, answer Θ(n^k).

      Step 4

      State the case alongside the bound — markers award the reasoning, not just the result.

      Real-life examples

      Homework check

      A student derives T(n) = 3T(n/2) + n for Karatsuba multiplication and wants to confirm the exponent before writing it up.

      log_2(3) = 1.585 > 1, Case 1, so T(n) = Theta(n^1.585) — faster than the schoolbook Theta(n^2), as expected.

      Karatsuba runs in Theta(n^1.585), confirmed.

      Choosing an optimisation

      An engineer's code follows T(n) = 2T(n/2) + n^2. Profiling suggests either halving the combine cost's constant or splitting into fewer subproblems.

      log_2(2) = 1 < 2, Case 3: the n^2 combine dominates, so cutting a subproblem changes nothing asymptotically; only reducing k helps.

      She optimises the combine step, not the recursion.

      Ideas & use cases

      • Algorithm shoot-outs: enter both recurrences for two candidate algorithms and compare dominant exponents before writing any code.
      • Constant-factor blindness check: if two designs land in the same case, the theorem cannot separate them — a cue to benchmark instead of theorise.
      • Exam rehearsal: cover the case column of the reference table and predict each classic algorithm's case before revealing it.

      Limitations & sources

      • Covers polynomial combine work Theta(n^k) only; f(n) with log factors, non-constant a or b, or subtractive recurrences (n − 1) need other methods, and Case 3's regularity condition is assumed, as it holds for all polynomials.

      Sources: Master theorem as stated in Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms (CLRS), ch. 4; Akra-Bazzi noted as the generalisation

      Master Theorem Calculator · TinyExe calculator suite Free to use · No sign-up · Instant results