Arithmetic and Geometric Progressions
Learning Objectives
- Recognize an arithmetic or geometric progression from a constant difference or a constant ratio, and write its -th term.
- Derive and use the closed forms for the sum of the first terms of each, including the special case and the correct count of terms.
- Decide the long-run behavior of for every real ratio , and tie it to convergence of a sequence.
- Translate loops into sums: nested loops give arithmetic sums, halving and doubling give geometric ones.
- Use a geometric sum to explain the cost of a doubling array and of compound growth, and contrast them with their arithmetic counterparts.
Context & Motivation
Among all sequences, two families have closed forms simple enough to handle exactly and common enough to appear in almost every cost analysis. In an arithmetic progression each term differs from the previous one by a fixed amount . In a geometric progression each term is a fixed multiple of the previous one. The first describes linear growth, the second exponential growth, and the contrast between them is the contrast between a loop that does a little more work each pass and a process that multiplies its size.
In the previous lesson, sequences-and-convergence, you learned what it means for a sequence to settle down. A progression is the easiest place to practice that definition, since the answer is known in closed form. The sums of progressions are also where the sequence turns into a new sequence of partial sums, the idea that the next lesson, infinite-series-and-partial-sums, builds on. The data-structures lesson dynamic-arrays-and-amortized-resizing argues that doubling a full array keeps appends cheap on average and that adding a fixed amount does not. This lesson supplies the arithmetic behind both claims and checks them with an actual count.
Core Theory
Arithmetic progressions
A sequence with for every is an arithmetic progression with first term and common difference . Its terms are
Its sum can be found by writing the sum twice, once forward and once backward, and adding the columns: every column adds to , and there are columns, so . Hence
The same formula can be proved by induction, as in mathematical-induction. The special case , gives . For the terms grow linearly in and the sums quadratically. If the sequence diverges (it grows without bound, upward or downward), and if it is constant.
Geometric progressions
A sequence with is a geometric progression with ratio :
For the sum, subtract from . Every term cancels except the first and the last, leaving , so
This formula divides by , so it does not apply when . In that case every term equals and . When the sum starts at the exponent , as in , there are terms and the formula reads . Counting terms wrongly is the most common error in applying it.
What does
The behavior of the sequence is the whole story for convergence of geometric progressions:
- If , then .
- If , the sequence is constant .
- If , it alternates between and and diverges.
- If , then . If , the terms alternate in sign and their size grows without bound, so it diverges.
To see the first case, note that is immediate; for , write with . Bernoulli's inequality gives , so , and the squeeze theorem finishes the proof. Consequently a geometric progression converges exactly when (to ) or (to ), provided . And when , the closed form shows the partial sums settling at , since (the next lesson turns this into a theorem about infinite series).
Loops, halving, and doubling
Counting the iterations of a program often means summing a progression. An inner loop whose bound grows by one each outer pass gives an arithmetic sum, hence in total. A quantity that is halved at each step, as in a loop while n > 1: n //= 2, runs times, and in a recursion that does work proportional to its input size and then recurses on half of it, the successive amounts form a geometric progression. In a geometric sum with the last term dominates: is less than twice the last term . That fact is what makes doubling cheap.
Worked Examples
Example 1: arithmetic sums from loops
The loop for i in range(n): for j in range(i): count += 1 runs the inner body times. Running it gives for , for , and for , matching the formula each time. It is about half of , yet still quadratic.
Now invert the question. For the progression (so , ), find the smallest with . Here , so we need . The positive root is . Check the neighbors: and . The answer is , whose last term is .
Example 2: geometric sums and the count of terms
For with terms, , :
For with terms, . Adding the ten terms directly gives the same number. The sum is , the largest number that fits in ten bits, since every bit set to contributes one power of two. The exponents through make terms, not .
Example 3: counting the copies of a doubling array
Each append to a full array copies every stored element into a larger array. The script below counts only those copies, starting from capacity , for two growth rules: doubling the capacity, and adding slots.
plaintextdef count_copies(n, grow): capacity, length, copies = 1, 0, 0 for _ in range(n): if length == capacity: # full: allocate a bigger array and copy copies += length capacity = grow(capacity) length += 1 # the append itself (one write) return copies for n in (10, 1_000, 10_000, 100_000, 1_000_000): dbl = count_copies(n, lambda c: 2 * c) inc = count_copies(n, lambda c: c + 16) print(f"{n:>9} doubling: {dbl:>9} ({dbl / n:.2f} per append) +16: {inc:>12} ({inc / n:.1f} per append)")
Its output:
text10 doubling: 15 (1.50 per append) +16: 1 (0.1 per append) 1000 doubling: 1023 (1.02 per append) +16: 31311 (31.3 per append) 10000 doubling: 16383 (1.64 per append) +16: 3120625 (312.1 per append) 100000 doubling: 131071 (1.31 per append) +16: 312456250 (3124.6 per append) 1000000 doubling: 1048575 (1.05 per append) +16: 31249562500 (31249.6 per append)
Doubling. The resizes happen when the length is , so the copies form the geometric sum , where is the final capacity, the smallest power of two that is at least . For that is , exactly the count. Since , the copies are always below , which is the bound used in dynamic-arrays-and-amortized-resizing. The ratio per append is not constant: it is at and at , because the array doubled to capacity at append , and the copies so far are spread over only appends. It stays under throughout.
Adding 16. The resizes happen at lengths , an arithmetic progression with . With , the copies total . For , and the total is , as counted. The cost per append grows like , so it keeps getting worse with .
This compares copies only. Doubling pays in memory: right after a resize up to half the array is unused, whereas adding wastes at most slots. And the factor is not special. Growing the capacity by any fixed factor keeps copies per append bounded by about , so factor (rounded up) measures per append at and factor measures . A smaller factor trades fewer unused slots for more copying.
Example 4: compound growth versus simple growth
Take an account holding with a fixed annual rate and annual compounding. Simple interest adds each year, an arithmetic progression: , which is after years. Compound interest multiplies by , a geometric one: equals after year, after , and after . The balance doubles when , at years (the rule of thumb is close).
Regular deposits form a geometric sum. Depositing at the end of each month for months at monthly rate gives , while the deposits themselves total . Applying the deposits one month at a time in a loop reproduces .
Common Misconceptions & Pitfalls
- Off-by-one in the number of terms. The sum has terms, and using in the exponent of the formula gives the wrong answer. Write the first and last exponent, count, and then substitute.
- Applying the geometric formula at . It divides by zero. The sum is , and this case matters because a loop with ratio exactly is just a loop.
- "The sum of an arithmetic progression is linear." For the terms are linear in and the sum is quadratic. A nested loop with a bound that grows with the outer counter is , even though the inner count is "only" .
- "A geometric progression with is dominated by its first terms." For the last term dominates, and the sum is a bounded multiple of it. For the first term dominates. That is why the copy costs of a doubling array add up to a small multiple of .
- "Amortized O(1) means each append is cheap." In Example 3 the append at length copies that many elements at once. The claim concerns the average over many appends, not any single one.
- "A ratio makes the terms tend to ." The terms alternate in sign with growing size, so the sequence has no limit at all, finite or infinite.
Summary
An arithmetic progression adds a fixed difference: and , so for terms grow linearly and sums quadratically. A geometric progression multiplies by a fixed ratio: and for , with at . The sequence tends to exactly when , which settles when a geometric progression converges. Counting terms carefully matters, because the same pattern gives or terms depending on where the exponent starts. In computing, nested loops produce arithmetic sums, halving produces steps, and doubling produces a geometric sum dominated by its last term, which is why a doubling array copies fewer than elements over appends while a fixed increment of copies about . Compound growth is the same geometric structure with money in place of memory. The next lesson, infinite-series-and-partial-sums, asks what happens to these sums when the number of terms is allowed to grow forever.