Solving a recurrence by unrolling

The running time of a simple loop-based algorithm satisfies T(n)=T(n−1)+nT(n) = T(n-1) + n for n≥2n \ge 2, with T(1)=1T(1) = 1. A student finds a closed form by repeatedly substituting the recurrence into itself, which is called unrolling or iteration. Put the student's steps in the order they must be carried out.

  1. 1.

    Evaluate the sum as T(n)=n(n+1)2T(n) = \dfrac{n(n+1)}{2}.

  2. 2.

    Substitute the recurrence for T(n−1)T(n-1) to get T(n)=T(n−2)+(n−1)+nT(n) = T(n-2) + (n-1) + n.

  3. 3.

    Choose k=n−1k = n-1 so that the remaining term is the base case T(1)T(1).

  4. 4.

    Prove the closed form for every n≥1n \ge 1 by induction.

  5. 5.

    Repeat the substitution and spot the pattern T(n)=T(n−k)+(n−k+1)+⋯+nT(n) = T(n-k) + (n-k+1) + \dots + n.

  6. 6.

    Replace T(1)T(1) with 11 to get T(n)=1+2+⋯+nT(n) = 1 + 2 + \dots + n.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Recurrence Relations Questions: