12–15 min read Sequences, Series & Recurrence Lesson 11 of 32
Part 2 — Discrete Mathematics

Lesson 14.11 — Sequences, Summations & Recurrence Relations

How many iterations will an algorithm's loops execute? How do we prove the asymptotic runtime of recursive functions? How do divide-and-conquer strategies break down massive problems? How does gradient descent iteratively update model parameters? The rigorous mathematical answer lies in Sequences, Summations, and Recurrence Relations.

1 Introduction: The Science of Sequential & Recursive Change

Imagine you are monitoring user acquisition for a software platform. On Day 1 you register 10 new users, on Day 2 you register 20, on Day 3 you register 30, and on Day 4 you register 40:

10, 20, 30, 40, 50, ... → Each term increases by a constant difference (+10)

Now consider a second scenario: Cloud backup storage utilization doubles each year. Year 1 requires 1,000 GB, Year 2 requires 2,000 GB, Year 3 requires 4,000 GB, and Year 4 requires 8,000 GB:

1000, 2000, 4000, 8000, 16000, ... → Each term is multiplied by a constant ratio (×2)

The first scenario exhibits an additive difference, while the second displays a multiplicative ratio. Furthermore, in many computational problems, the current state is explicitly defined by one or more prior states — such as the Fibonacci numbers or Merge Sort.

Sequence

Ordered Lists of Terms

An ordered collection of numbers following a deterministic rule, indexed by integer positions.

Summation (\(\sum\))

Accumulating Total Output

A concise mathematical operator for expressing and computing the total sum of sequence terms.

Recurrence Relation

Inductive Dependencies

An equation defining each term as a function of preceding terms, underpinning recursion and Dynamic Programming.

2 What is a Sequence?

Mathematically, a Sequence is a function whose domain is a subset of integers (usually \(\mathbb{N} = \{1, 2, 3, \dots\}\) or \(\mathbb{N}_0 = \{0, 1, 2, \dots\}\)) and whose codomain is a set of real numbers or algebraic objects.

The output values are called terms, denoted as \(a_1, a_2, a_3, \dots, a_n\), where the subscript indicates the term's index or position.

Example: Even Integers Sequence
\( 2, 4, 6, 8, 10, \dots \)
1st term: \(a_1 = 2\)
2nd term: \(a_2 = 4\)
3rd term: \(a_3 = 6\)
4th term: \(a_4 = 8\)
Finite Sequence

Contains a finite, fixed number of terms. Example: \( 2, 4, 6, 8, 10 \) (length = 5).

Infinite Sequence

Continues indefinitely without bound. Example: \( 2, 4, 6, 8, 10, \dots \) (indicated by ellipses).

2.1 The General Term (\(a_n\))

The formula that maps the integer position \(n\) directly to the value of the \(n\)-th term is known as the General Term. For example, if \(a_n = 2n\), the 100th term is directly evaluated as \(a_{100} = 2(100) = 200\).

💡 Essential Distinction from Sets:

In sets, order and multiplicity are ignored (\(\{2, 4\} = \{4, 2\}\)). In sequences, order and position are paramount — \((2, 4, 6)\) and \((4, 2, 6)\) represent two entirely different sequences!

3 Arithmetic Sequences (Arithmetic Progressions - AP)

An Arithmetic Sequence is a sequence of numbers in which the difference between consecutive terms is constant.

This constant value is called the Common Difference (\(d\)):

\[ d = a_n - a_{n-1} \]

Example: In the sequence \( 3, 7, 11, 15, 19, \dots \): \( 7 - 3 = 4 \), \( 11 - 7 = 4 \), \( 15 - 11 = 4 \). Therefore, the common difference is \( d = 4 \).

3.1 General Formula for the \(n\)-th Term

Starting from the initial term \(a_1\) and adding \(d\) repeatedly:

\(a_1 = a_1\)
\(a_2 = a_1 + d\)
\(a_3 = a_2 + d = a_1 + 2d\)
\(a_4 = a_3 + d = a_1 + 3d\)

By mathematical induction, the closed-form formula for the \(n\)-th term is:

\[ a_n = a_1 + (n - 1)d \]
Worked Example: Computing the 20th Term

Given the sequence \( 5, 8, 11, 14, 17, \dots \), find the 20th term.

First term \(a_1 = 5\), common difference \(d = 8 - 5 = 3\), and \(n = 20\).
\[ a_{20} = 5 + (20 - 1) \times 3 = 5 + 19 \times 3 = 5 + 57 = 62 \]

3.2 Behavior Governed by \(d\)

  • \(d > 0\): Strictly Increasing. Example: \(2, 5, 8, 11, \dots\) (\(d=3\)).
  • \(d \\lt 0\): Strictly Decreasing. Example: \(20, 16, 12, 8, \dots\) (\(d=-4\)).
  • \(d = 0\): Constant Sequence. Example: \(7, 7, 7, 7, \dots\) (\(d=0\)).

4 Geometric Sequences (Geometric Progressions - GP)

A Geometric Sequence is a sequence in which each term after the first is found by multiplying the previous term by a fixed, non-zero number.

This fixed factor is called the Common Ratio (\(r\)):

\[ r = \frac{a_n}{a_{n-1}} \quad (a_{n-1} \ne 0) \]

Example: In the sequence \( 2, 6, 18, 54, 162, \dots \): \( \frac{6}{2} = 3 \), \( \frac{18}{6} = 3 \), \( \frac{54}{18} = 3 \). Thus, the common ratio is \( r = 3 \).

4.1 General Formula for the \(n\)-th Term

Given initial term \(a_1\) and common ratio \(r\):

\(a_1 = a_1\)
\(a_2 = a_1 \cdot r\)
\(a_3 = a_2 \cdot r = a_1 \cdot r^2\)
\(a_4 = a_3 \cdot r = a_1 \cdot r^3\)

By mathematical induction, the closed-form formula for the \(n\)-th term is:

\[ a_n = a_1 r^{n - 1} \]
Worked Example: Computing the 8th Term

Given the geometric sequence \( 3, 6, 12, 24, 48, \dots \), find the 8th term.

First term \(a_1 = 3\), common ratio \(r = \frac{6}{3} = 2\), and \(n = 8\).
\[ a_8 = 3 \times 2^{8 - 1} = 3 \times 2^7 = 3 \times 128 = 384 \]

4.2 Dynamics Dictated by \(r\)

  • \(r > 1\): Exponential Explosion (\(O(r^n)\)). E.g., binary tree node counts \(1, 2, 4, 8, \dots\) (\(r=2\)).
  • \(0 \\lt r \\lt 1\): Exponential Decay towards 0. E.g., discount factor decaying reward horizons (\(r=0.5\)).
  • \(r \\lt 0\): Alternating Sequence (signs oscillate between positive and negative). E.g., \(1, -2, 4, -8, 16, \dots\).

5 Arithmetic vs. Geometric Sequences: Comparative Analysis

Dimension Arithmetic Sequence (AP) Geometric Sequence (GP)
Defining Operation Constant Addition/Subtraction (\(+d\)) Constant Multiplication/Division (\(\times r\))
Recurrence Formulation \(a_n = a_{n-1} + d\) \(a_n = r \cdot a_{n-1}\)
\(n\)-th Term Closed Form \(a_n = a_1 + (n-1)d\) \(a_n = a_1 r^{n-1}\)
Asymptotic Growth Rate Linear Growth (\(O(n)\)) Exponential Growth (\(O(r^n)\))
Computer Science Applications Linear array offsets, simple loop counters Binary search tree partitioning, cryptographic keyspaces

6 Summations and Sigma Notation (\(\sum\))

The operation of adding the terms of a sequence is called a Summation. To express sums of hundreds or millions of algorithmic iterations compactly, mathematicians and computer scientists use the Greek capital letter \(\Sigma\) (Sigma).

Anatomy of Sigma Notation
\[ \sum_{i=1}^{n} a_i = a_1 + a_2 + a_3 + \dots + a_n \]
\(\Sigma\): Summation operator
\(i\): Index of summation (loop counter)
\(1\): Lower bound (start index)
\(n\): Upper bound (termination index)

6.1 Linear Algebraic Properties of Summations

1. Homogeneity (Scalar Multiplication)
\( \sum c \cdot a_i = c \sum a_i \)

Constant coefficients factor outside the summation.

2. Additivity (Sum Splitting)
\( \sum (a_i + b_i) = \sum a_i + \sum b_i \)

A sum of compound terms decomposes into individual sums.

3. Sum of a Constant
\( \sum_{i=1}^{n} c = c + c + \dots + c = n \cdot c \)

Summing a constant value \(c\) exactly \(n\) times equals \(n \times c\).

7 Essential Summation Formulas in Computer Science

When evaluating nested loops and proving Big-\(O\) time complexity bounds, these 5 closed-form summation formulas are indispensable:

1. Sum of First \(n\) Positive Integers Gauss's Formula
\[ \sum_{i=1}^{n} i = 1 + 2 + 3 + \dots + n = \frac{n(n + 1)}{2} \]

Impact: In algorithms like Bubble Sort or Selection Sort, nested triangular loops execute \(\frac{n(n-1)}{2} = \Theta(n^2)\) operations.

2. Sum of First \(n\) Squares Sum of Squares
\[ \sum_{i=1}^{n} i^2 = 1^2 + 2^2 + 3^2 + \dots + n^2 = \frac{n(n + 1)(2n + 1)}{6} \]

Example: \(1^2 + 2^2 + 3^2 + 4^2 = 30 = \frac{4(5)(9)}{6}\). Critical when analyzing triply nested algorithms (\(O(n^3)\)).

3. Sum of First \(n\) Cubes Nicomachus's Theorem
\[ \sum_{i=1}^{n} i^3 = 1^3 + 2^3 + 3^3 + \dots + n^3 = \left(\frac{n(n + 1)}{2}\right)^2 = \left(\sum_{i=1}^n i\right)^2 \]

The sum of cubes of consecutive integers is exactly the square of their linear sum!

4. Sum of an Arithmetic Progression (AP Series) AP Series Sum
\[ S_n = \frac{n}{2}\left[2a_1 + (n - 1)d\right] = \frac{n}{2}(a_1 + a_n) \]

When the first and last terms are known, directly apply \(\frac{n}{2}(\text{first} + \text{last})\).

5. Sum of a Finite Geometric Series (GP Series) GP Series Sum
\[ S_n = a_1 \frac{1 - r^n}{1 - r} = a_1 \frac{r^n - 1}{r - 1} \quad (r \ne 1) \]

Example: For \( 2, 4, 8, 16, 32 \) (\(a_1=2, r=2, n=5\)): \( S_5 = 2 \frac{2^5 - 1}{2 - 1} = 2(31) = 62 \).

8 What is a Recurrence Relation?

A Recurrence Relation is an equation that recursively defines a sequence by expressing each term as a function of one or more of its preceding terms.

Two Essential Pillars of a Recurrence Relation:

1. Initial Condition (Base Case)

Anchors the start of the sequence (e.g. \(a_1 = 2\)). Without a base case, infinitely many distinct sequences satisfy the relation.

2. Recurrence Equation

The inductive rule for computing the next term from previous values (e.g. \(a_n = a_{n-1} + 3\)).

9 Recursive vs. Explicit Formulas (Closed-Form)

Any sequential computational process can be represented from two complementary mathematical viewpoints:

Recursive Representation
\(a_1 = 3\)
\(a_n = a_{n-1} + 2, \quad n \ge 2\)

Finding the 100th term requires computing all 99 intermediate terms sequentially from the ground up (\(O(n)\) computational cost).

Explicit Formula (Closed-Form)
\(a_n = 2n + 1\)

Directly computes the term value for any position index without intermediate iterations (\(a_{100} = 2(100) + 1 = 201\) in \(O(1)\) time).

10 The Fibonacci Sequence

The most renowned second-order recurrence in computer science is the Fibonacci Sequence:

Formal Recurrence Definition 2nd Order Recurrence
\[ F_0 = 0, \quad F_1 = 1 \] \[ F_n = F_{n-1} + F_{n-2} \quad (n \ge 2) \]

Each term is the sum of its two immediate predecessors:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
Optimized Iterative Fibonacci in Python:
def fibonacci(n):
    if n == 0: return 0
    a, b = 0, 1
    for _ in range(2, n + 1):
        a, b = b, a + b
    return b

print(fibonacci(10))  # Output: 55 (O(n) Time, O(1) Space)

11 Factorial as a Recurrence & The Call Stack

The factorial function is natively formulated as a first-order recurrence:

\[ 0! = 1 \] \[ n! = n \times (n - 1)! \quad (n \ge 1) \]

⚠️ Call Stack & Stack Overflow Danger:

In recursive software implementations, every self-invocation allocates a stack frame in system memory. Without a terminating base case (\(n == 0\)), stack memory exhausts, triggering a catastrophic StackOverflowError.

12 Recurrence Relations & Algorithm Complexity (Divide & Conquer)

Recurrence relations are the primary mathematical instrument for analyzing Divide-and-Conquer algorithms:

1. Merge Sort

Splits an array of size \(n\) into 2 halves (\(n/2\)) and performs linear \(O(n)\) merging work:

\[ T(n) = 2T(n/2) + \Theta(n) \]

By the Master Theorem, solving this recurrence yields: \( \Theta(n \log n) \).

2. Binary Search

Performs 1 comparison and halves the search space at each iteration:

\[ T(n) = T(n/2) + \Theta(1) \]

Solving this yields the definitive logarithmic runtime: \( \Theta(\log n) \).

13 Infinite Geometric Series & Convergence

Does summing an infinite number of terms (\(a + ar + ar^2 + \dots\)) always yield infinity? No! When the absolute value of the common ratio is strictly less than 1 (\(|r| \\lt 1\)), the terms decay rapidly toward zero, causing the infinite sum to converge to a finite limit:

Sum of an Infinite Geometric Series Condition: |r| < 1
\[ S_\infty = \frac{a_1}{1 - r} \quad (|r| \\lt 1) \]
Classic Case (Zeno's Dichotomy Paradox):
\[ 1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \dots = \frac{1}{1 - \frac{1}{2}} = \frac{1}{0.5} = 2 \]

Despite adding infinitely many fractional steps, the total sum never exceeds 2!

14 Real-World Applications in Computer Science & AI

1. Dynamic Programming & Memoization

When a recurrence relation contains Overlapping Subproblems (such as naive recursive Fibonacci repeatedly recomputing \(F_3\) and \(F_4\)), naive recursion leads to an exponential catastrophe (\(O(2^n)\)). Dynamic Programming eliminates redundant work via memoization or bottom-up tabulation, reducing execution time to linear \(O(n)\).

2. Prefix Sum Arrays in High-Throughput Analytics

To query cumulative metrics over arbitrary intervals \([L, R]\) without iterating through arrays on each request, data engines precompute prefix sums \(P[k] = \sum_{i=0}^k A[i]\). Range queries then resolve in \(O(1)\) constant time via \(\text{RangeSum}(L, R) = P[R] - P[L-1]\).

3. Reinforcement Learning Discounted Returns

In Reinforcement Learning, an agent values immediate rewards higher than distant future rewards using discount factor \(\gamma \lt 1\). The expected cumulative return is formulated as an infinite geometric series: \( G_t = \sum_{k=0}^\infty \gamma^k R_{t+k+1} \). Because \(\gamma \lt 1\), the infinite series is guaranteed to converge to a bounded, stable scalar.

4. Gradient Descent Trajectories in Machine Learning

Deep neural network training relies on iterative weight parameter updates defined as a first-order recurrence relation:

\[ w_{t+1} = w_t - \alpha \nabla L(w_t) \]

where \(w_t\) is the current weight vector, \(\alpha\) is the learning rate scalar, and \(\nabla L\) is the loss gradient vector.

15 Common Pitfalls & Traps

Pitfall 1: Confusing AP and GP

Confusing constant differences (\(+d\)) with constant ratios (\(\times r\)). Rule of thumb: test differences first; if unequal, test quotients.

Pitfall 2: Equating \(n\)-th Term (\(a_n\)) with Sum (\(S_n\))

\(a_{10}\) denotes the single scalar value at position 10; \(S_{10}\) represents the aggregated cumulative sum of all terms from 1 to 10.

Pitfall 3: Writing \(nd\) instead of \((n-1)d\) in AP Formulas

The initial term receives zero additions of \(d\) (\(1 - 1 = 0\)). The formula is always \(a_1 + (n - 1)d\), never \(a_1 + nd\).

Pitfall 4: Omitting the Base Case in Recurrences

Writing \(a_n = 2a_{n-1}\) without defining \(a_1\) fails to specify a unique sequence. An initial anchor is mathematically required.

Pitfall 5: Missing Base Cases in Recursive Functions

Without a base case, recursion exhausts the OS call stack, causing an unrecoverable stack overflow crash.

Pitfall 6: Applying Infinite Sum to Divergent GP

The formula \(S_\infty = \frac{a_1}{1-r}\) is mathematically valid strictly when \(|r| \\lt 1\). If \(r = 2\), the series diverges to infinity.

16 Interactive Workbench: Sequences & Recurrences Playground

Use these 3 interactive laboratories to visualize arithmetic and geometric sequences, contrast exponential recursive explosions against Dynamic Programming, and simulate divide-and-conquer algorithm complexities:

Arithmetic & Geometric Sequence Live Simulator

Toggle sequence types, modify parameters, and observe individual term values, cumulative sums, and convergence behavior.

First Term (\(a_1\)): 2
Common Difference (\(d\)): 3
Term Count (\(n\)): 8
Generated Sequence Terms:
General Term (a_n)
23
Sum of n Terms (S_n)
100
Infinite Sum (S_\infty)
N/A (Divergent)

17 Key Takeaways

1. Arithmetic Sequences

Consecutive terms differ by a constant difference (\(d\)). Closed form: \(a_n = a_1 + (n-1)d\). Represents linear growth.

2. Geometric Sequences

Consecutive terms scale by a constant ratio (\(r\)). Closed form: \(a_n = a_1 r^{n-1}\). Represents exponential growth.

3. Gauss Summation

Sum of the first \(n\) positive integers: \(\sum i = \frac{n(n+1)}{2}\). The foundation of loop counting and quadratic complexity.

4. Series Sum Formulas

AP sum: \(S_n = \frac{n}{2}(a_1 + a_n)\). GP sum: \(S_n = a_1 \frac{r^n-1}{r-1}\).

5. Recurrence Relations

Equations defining subsequent terms from previous values. Must include base cases (initial conditions) to be uniquely determined.

6. Fibonacci & DP

\(F_n = F_{n-1} + F_{n-2}\). Incurs \(O(2^n)\) under naive recursion, but collapses to \(O(n)\) via Dynamic Programming tabulation.

7. Divide & Conquer

Merge Sort: \(T(n) = 2T(n/2) + n \implies \Theta(n \log n)\). Binary Search: \(T(n/2) + 1 \implies \Theta(\log n)\).

8. Infinite Series

When \(|r| \\lt 1\), the infinite geometric series converges to a finite limit: \(S_\infty = \frac{a_1}{1 - r}\).

9. AI & Optimization

Gradient descent parameter trajectory \(w_{t+1} = w_t - \alpha \nabla L\) and RL discounted reward horizons are direct recurrences.