cs.thefarshad
medium

Sequences & Series

Arithmetic and geometric sequences, partial sums, and how a series converges to a limit or diverges to infinity.

A sequence is an ordered list of numbers; a series is what you get when you add them up. Deciding whether an infinite sum settles to a finite value or grows without bound is a core question — and it mirrors how recursive costs accumulate and how iterative methods either converge to an answer or blow up.

Pick a series below and press Accumulate. Each step adds one more term to the running partial sum (the gold dot). Watch convergent series home in on the dashed limit while divergent ones march off the chart.

converges
limit = 1.000
n = 1/28
partial sum S(1) ≈ 0.5000distance to limit ≈ 0.5000

ratio r = 1/2 < 1 → converges to a/(1−r) = 1.

Arithmetic sequences

An arithmetic sequence adds a fixed common difference dd each step: a, a+d, a+2d, a,\ a+d,\ a+2d,\ \dots, so the nn-th term is an=a+(n1)da_n = a + (n-1)d. Its partial sum has a tidy closed form:

Sn=n2(a1+an).S_n = \frac{n}{2}\,(a_1 + a_n).

Pairing the first and last terms — the trick Gauss famously used — is why 1+2++n=n(n+1)21 + 2 + \cdots + n = \frac{n(n+1)}{2}.

Geometric sequences

A geometric sequence multiplies by a fixed ratio rr each step: a, ar, ar2, a,\ ar,\ ar^2,\ \dots, with an=arn1a_n = a\,r^{n-1}. The partial sum is

Sn=a1rn1r.S_n = a\,\frac{1 - r^n}{1 - r}.

When r<1|r| < 1, the term rnr^n shrinks to zero, so the infinite sum converges:

n=0arn=a1r(r<1).\sum_{n=0}^{\infty} a\,r^n = \frac{a}{1 - r} \quad (|r| < 1).

That is exactly why 12+14+18+=1\frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \cdots = 1 in the visualizer — each term covers half the remaining gap.

Convergence and divergence

A series converges if its partial sums approach a finite limit, and diverges otherwise. A geometric series converges precisely when r<1|r| < 1. A necessary first check: if the terms do not shrink to zero, the series cannot converge. But shrinking terms are not enough — the harmonic series 1/n\sum 1/n diverges even though its terms vanish, because they shrink too slowly. Sign matters too: the alternating harmonic series (1)n+1/n\sum (-1)^{n+1}/n converges to ln2\ln 2.

Why it matters for CS

Geometric series quantify the cost of doubling strategies: a dynamic array that grows by doubling does 1+2+4++n2n1 + 2 + 4 + \cdots + n \approx 2n total copies, so each insertion is O(1)O(1) amortized. Convergence underlies iterative numerical methods — gradient descent and Newton’s method are useful only when their step sequence converges. Geometric decay also models exponential backoff and the resolution of recurrences.

References

Takeaways

  • Arithmetic sequences add a constant dd; geometric sequences multiply by a ratio rr, each with a closed-form partial sum.
  • A geometric series converges to a1r\frac{a}{1-r} exactly when r<1|r| < 1.
  • Vanishing terms are necessary but not sufficient — the harmonic series diverges even as its terms shrink to zero.