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:
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:
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.
Ordered Lists of Terms
An ordered collection of numbers following a deterministic rule, indexed by integer positions.
Accumulating Total Output
A concise mathematical operator for expressing and computing the total sum of sequence terms.
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.
Contains a finite, fixed number of terms. Example: \( 2, 4, 6, 8, 10 \) (length = 5).
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\)):
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:
By mathematical induction, the closed-form formula for the \(n\)-th term is:
Given the sequence \( 5, 8, 11, 14, 17, \dots \), find the 20th term.
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\)):
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\):
By mathematical induction, the closed-form formula for the \(n\)-th term is:
Given the geometric sequence \( 3, 6, 12, 24, 48, \dots \), find the 8th term.
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).
6.1 Linear Algebraic Properties of Summations
Constant coefficients factor outside the summation.
A sum of compound terms decomposes into individual sums.
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:
Impact: In algorithms like Bubble Sort or Selection Sort, nested triangular loops execute \(\frac{n(n-1)}{2} = \Theta(n^2)\) operations.
Example: \(1^2 + 2^2 + 3^2 + 4^2 = 30 = \frac{4(5)(9)}{6}\). Critical when analyzing triply nested algorithms (\(O(n^3)\)).
The sum of cubes of consecutive integers is exactly the square of their linear sum!
When the first and last terms are known, directly apply \(\frac{n}{2}(\text{first} + \text{last})\).
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:
Anchors the start of the sequence (e.g. \(a_1 = 2\)). Without a base case, infinitely many distinct sequences satisfy the relation.
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:
\(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).
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:
Each term is the sum of its two immediate predecessors:
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:
⚠️ 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:
Splits an array of size \(n\) into 2 halves (\(n/2\)) and performs linear \(O(n)\) merging work:
By the Master Theorem, solving this recurrence yields: \( \Theta(n \log n) \).
Performs 1 comparison and halves the search space at each iteration:
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:
Despite adding infinitely many fractional steps, the total sum never exceeds 2!
14 Real-World Applications in Computer Science & AI
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)\).
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]\).
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.
Deep neural network training relies on iterative weight parameter updates defined as a first-order recurrence relation:
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
Confusing constant differences (\(+d\)) with constant ratios (\(\times r\)). Rule of thumb: test differences first; if unequal, test quotients.
\(a_{10}\) denotes the single scalar value at position 10; \(S_{10}\) represents the aggregated cumulative sum of all terms from 1 to 10.
The initial term receives zero additions of \(d\) (\(1 - 1 = 0\)). The formula is always \(a_1 + (n - 1)d\), never \(a_1 + nd\).
Writing \(a_n = 2a_{n-1}\) without defining \(a_1\) fails to specify a unique sequence. An initial anchor is mathematically required.
Without a base case, recursion exhausts the OS call stack, causing an unrecoverable stack overflow crash.
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.
17 Key Takeaways
Consecutive terms differ by a constant difference (\(d\)). Closed form: \(a_n = a_1 + (n-1)d\). Represents linear growth.
Consecutive terms scale by a constant ratio (\(r\)). Closed form: \(a_n = a_1 r^{n-1}\). Represents exponential growth.
Sum of the first \(n\) positive integers: \(\sum i = \frac{n(n+1)}{2}\). The foundation of loop counting and quadratic complexity.
AP sum: \(S_n = \frac{n}{2}(a_1 + a_n)\). GP sum: \(S_n = a_1 \frac{r^n-1}{r-1}\).
Equations defining subsequent terms from previous values. Must include base cases (initial conditions) to be uniquely determined.
\(F_n = F_{n-1} + F_{n-2}\). Incurs \(O(2^n)\) under naive recursion, but collapses to \(O(n)\) via Dynamic Programming tabulation.
Merge Sort: \(T(n) = 2T(n/2) + n \implies \Theta(n \log n)\). Binary Search: \(T(n/2) + 1 \implies \Theta(\log n)\).
When \(|r| \\lt 1\), the infinite geometric series converges to a finite limit: \(S_\infty = \frac{a_1}{1 - r}\).
Gradient descent parameter trajectory \(w_{t+1} = w_t - \alpha \nabla L\) and RL discounted reward horizons are direct recurrences.