DSATime ComplexityInduction

Substitution Method Visualizer

What is the Substitution Method

Substitution is guess-and-check by induction. You propose T(n) ≤ c · g(n), assume it for smaller inputs, substitute into the recurrence, and choose c so the inequality closes. It proves a bound the tree only suggested.

  • Guess the shape (often from a recursion tree).
  • Base case fixes a minimum c.
  • Inductive step is algebra — leftover positive terms mean the guess is too tight or c is too small.

How this visualizer works

We prove T(n)=2T(n/2)+n is O(n log n). Change c and watch the leftover term n(1−c) flip from failing to closing.

Interactive substitution proof

induction_board

current_action

We prove T(n) = 2T(n/2)+n is O(n log n) by induction.

proof.py

1Guess T(n) ≤ c n log n for n ≥ 2
2Base: T(2) = 2 ≤ c·2·1 → pick c ≥ 1
3Assume T(n/2) ≤ c (n/2) log(n/2)
4Substitute: T(n) ≤ 2·[c(n/2)log(n/2)] + n
5 = c n (log n − 1) + n
6 = c n log n − c n + n
7Need −c n + n ≤ 0 → c ≥ 1
8Hold the same c. Therefore T(n) = O(n log n)

algebra log

Ready

Why substitution

Guess a closed form, assume it holds for smaller n, plug into the recurrence, and choose a constant that makes the algebra close. If the leftover term is negative, the guess is tight enough.

complexity.md

OperationTime
GuessO(n log n)
Induction stepalgebra on T(n/2)
Verified boundO(n log n)
Space—