Computer Science
Advanced

Master Theorem Form

General form for analyzing divide-and-conquer recurrences.

Formula

T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n)

Variables

aSubproblems
bDivision factor
f(n)Extra work

Example

Solves many recursive runtimes

How it works

This recurrence describes a problem that splits into a subproblems, each of size n/b, and then spends f(n) time doing the non-recursive work such as dividing the input and combining the results. It works because many divide-and-conquer algorithms build a recursion tree with the same branching pattern at each level, so the total time can be estimated by comparing the work done across all levels. The Master Theorem gives a fast way to decide whether the recursion is dominated by the branching, the combining work, or a balance between the two.

When to use it

Use this form when analyzing recursive divide-and-conquer algorithms like mergesort, Karatsuba-style multiplication, or recursive search/partition algorithms where the input is split into equal-sized pieces. It is most useful when the recurrence matches exact or near-exact equal subproblem sizes and the extra work can be expressed as a simple function of n.

Worked example, step by step

Solve T(n) = 2T(n/2) + n Step 1: Identify the parameters: a = 2, b = 2, f(n) = n Step 2: Compute n^(log_b a) = n^(log_2 2) = n^1 = n Step 3: Compare f(n) with n^(log_b a): both are n, so they match Step 4: By the balanced case of the Master Theorem, T(n) = Θ(n log n) Final answer: T(n) = Θ(n log n)

Common mistakes to avoid

  • Forgetting that a is the number of subproblems, not the number of recursive calls including base cases
  • Using the theorem when subproblem sizes are not equal to n/b, or when the recurrence is not in the required form
  • Comparing f(n) to n^(log_b a) incorrectly, especially when logarithms or lower-order terms are involved

Did You Know?

The Master Theorem instantly reveals the runtime of most divide-and-conquer algorithms.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026