core30 min studyLesson 232 in Mathematics

Asymptotic bounds and recurrence solving

State resource bounds with quantifiers, solve recurrences by expansion and induction, and account for input encoding.

On this page

What you’ll understand

  • Distinguish an upper bound from an asymptotically tight bound.
  • Solve a recurrence and verify its initial conditions.
  • Explain why arithmetic-operation counts can differ from bit complexity.

Saying that an algorithm is fast hides three questions: which inputs, which resource, and which machine operations? Asymptotic notation answers a carefully specified growth question after those choices are made. It suppresses fixed constants without removing quantifiers. Recurrences then record how a procedure pays for smaller instances. Expanding a few terms can suggest a pattern, but a checked boundary case and an inductive argument turn that pattern into a reliable resource bound.

Attach quantifiers to the growth claim

For eventually nonnegative functions, f belongs to O(g) when one positive constant times g bounds f above for every sufficiently large input size. Omega reverses the inequality; Theta requires both directions. A quadratic function is also O(n cubed), so an upper bound alone need not identify its growth rate tightly. The constants and starting threshold may depend on a fixed algorithm, but not on the growing size n. Small benchmark differences do not contradict an eventual bound.

Define the cost function before bounding it. Worst-case time at size n maximizes over all permitted inputs of that size. Best-case time minimizes instead; expected time requires a stated probability space. An array scan can be constant-time on its best input and linear-time in its worst case. The word average is incomplete without saying whether inputs are sampled or the algorithm itself tosses coins. Space bounds likewise distinguish input storage, auxiliary storage, and recursion-stack depth.

f∈O(g)  ⟺  (∃c>0)(∃n0)(∀n≥n0) 0≤f(n)≤c g(n)f\in O(g)\iff (\exists c>0)(\exists n_0)(\forall n\ge n_0)\ 0\le f(n)\le c\,g(n)
The bound is uniform over all sufficiently large sizes. Theta additionally requires a positive constant lower bound of the same form.↔ Scroll wide equations horizontally.

Expand, guess, and verify

Suppose a procedure removes one item and then performs work equal to the current size. With base cost T(1) = 1 and recurrence T(n) = T(n−1) + n for integers n at least two, repeated expansion sums the integers from one through n. Pairing the first and last terms gives the familiar triangular number. The result is Theta(n squared), because its ratio to n squared stays between two positive constants for all positive n.

An induction is short but still useful. Substitute the proposed expression for T(n−1), add n, and simplify to the expression at n. Check n = 1 separately. For inequalities, choose constants large enough to absorb base costs and lower-order terms rather than pretending an asymptotic expression is an exact equation. A common mistake is to use the desired bound in an inductive hypothesis too weak to close the next step; strengthening the hypothesis can repair the proof.

T(n)=∑j=1nj=n(n+1)2,12n2≤T(n)≤n2(n≥1)T(n)=\sum_{j=1}^{n}j=\frac{n(n+1)}2,\qquad \frac12n^2\le T(n)\le n^2\quad(n\ge1)
The exact expression follows from the given base case and recurrence. The two inequalities establish a tight quadratic bound.↔ Scroll wide equations horizontally.

Input length and the cost of a number

In a word-RAM analysis, operations on words of logarithmic size in the problem dimensions are usually charged constant time within the declared instruction set. Arbitrarily large integers do not fit that assumption. Adding two b-bit integers by the ordinary digitwise method takes O(b) bit operations. A recurrence counting one addition per stage can therefore understate the bit cost when intermediate values grow. Resource analyses are model-relative statements, not properties of source-code line counts alone.

Encoding also changes what polynomial means. A positive integer N written in binary needs roughly log base two of N bits. Performing N iterations is linear in its numeric value but exponential in its bit length on some inputs. Such a running time is called pseudopolynomial when polynomial dependence on numeric magnitudes replaces polynomial dependence on their encoded lengths. This distinction later prevents a knapsack table indexed by capacity from becoming an accidental proof that an NP-complete decision problem has a polynomial-time algorithm.

Count every level of repeated halving

Let T(1) = 2 and T(n) = T(n/2) + 3 for powers of two n. Find an exact formula, a tight asymptotic bound, and the value at n = 32.

  1. Write n = 2^k. Repeated substitution reaches the base case after k halvings, and each nonbase call contributes exactly three cost units.

  2. Thus T(2^k) = 2 + 3k. The case k = 0 gives two, matching the base case; adding one halving increases the expression by three as required.

  3. For n = 32, k = 5, so T(32) = 17. Since k = log₂ n, the formula is Theta(log n) as n grows through powers of two; the constant base cost matters only at the boundary.

The result

The exact cost is 2 + 3 log₂ n on the stated domain. The recurrence counts one recursive child per call, not every node of a branching tree.

Explore the model

Interactive lab

Interactive lab · root-finding

See logarithmic refinement without confusing it with runtime

Pause and reset, then set both controls to target c = 2 and upper bound U = 4. Predict that each noncollapsing bisection halves the bracket width; use Step to compare the error bound over several refinements. For a fresh run, pause and reset, then set c = 2 and U = 2. The initial bracket is half as wide, so a matching number of refinements gives half the width unless exact root detection collapses it. This model refines one quadratic bracket; it does not measure general program time or arbitrary-precision arithmetic.

See logarithmic refinement without confusing it with runtimeBisection of x² − c on [0,U], capped at 50 iterations for floating-point resolution. The error bound is the maximum distance from the displayed midpoint to either bracket endpoint (half the width in exact arithmetic). Compensated square evaluation preserves the bracket when ordinary multiplication rounds a residual to zero. A truly exact endpoint or midpoint collapses the bracket. This is one monotone quadratic, not a general root solver. Current readings: Midpoint after 0 refinements: 1.5; Bracket error bound: 1.5; Computed residual · x² − c: 0.25. All parameters are adjustable with the labeled controls below.Bisection on x squared minus 2: bracket from 0 to 3 after 0 refinements.00.751.52.253−2.360.192.745.297.84x · bracket stays nonnegativef(x) = x² − cn = 0 · [ 0, 3 ]
Quadratic / midpointCurrent bracketPositive root
Midpoint after 0 refinements
1.5
Bracket error bound
1.5
Computed residual · x² − c
0.25
t = 0 s

Bisection of x² − c on [0,U], capped at 50 iterations for floating-point resolution. The error bound is the maximum distance from the displayed midpoint to either bracket endpoint (half the width in exact arithmetic). Compensated square evaluation preserves the bracket when ordinary multiplication rounds a residual to zero. A truly exact endpoint or midpoint collapses the bracket. This is one monotone quadratic, not a general root solver. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forGeometric shrinkage leads to a logarithmic count of refinement stages, after the per-stage cost is specified.

Check your understanding

An algorithm performs N constant-cost iterations when N is a binary-encoded input integer. Which conclusion is justified?

Try it yourself

Solve S(0) = 4 and S(n) = S(n−1) + 2n + 1 for integers n at least one. Give an exact value at n = 3 and explain why the leading term alone does not determine that value.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Sum the increment from one through n, keeping the base cost outside the sum.

Compare with the solution

Expansion gives S(n) = 4 + 2(1 + … + n) + n = n² + 2n + 4. Substitution at n−1 verifies the recurrence, and n = 0 gives four. Consequently S(3) = 9 + 6 + 4 = 19 and S belongs to Theta(n²). The tight asymptotic class discards the linear and constant terms; it therefore cannot recover the exact value 19 without the recurrence and base condition.

Take it with you

  • O is an eventual upper bound, while Theta states matching upper and lower growth.
  • A recurrence needs a domain, base cases, and a clear counted resource.
  • Polynomial time refers to encoded input length under a stated computational model.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.