Geometric sequences
easy 15 minA geometric sequence multiplies by the same ratio every step: 1, 2, 4, 8 or 64, 32, 16, 8.
Video lesson · Chapter 1 of 5
The recorder fills unevenly
Geometric sequences
1:22Reel
Read caption
Otto doubles a photo array, then accounts for fifteen moves across its first nine appends. Double the space. One copy buys a run of cheap writes.
How it works
Step through the idea, or press Play.
Multiply by r. Each term is the previous one times a fixed ratio r: 2, 6, 18, 54 has r = 3
Understand it
Start here
What a geometric sequence is
A geometric sequence (also called a geometric progression, GP) is a list of numbers where each term is the previous term multiplied by the same constant, the common ratio . Start at 2 and keep multiplying by 3: . Divide any term by the one before it and you always get 3.
The pattern
Growth:
Each term is bigger: with . Recursion trees and doubling arrays.
Decay:
Each term is smaller: with . Binary search and halving loops.
Flat:
Every term is the same: . The sum is just .
Alternating:
Signs flip each step: with .
Add or multiply
Arithmetic against geometric
An arithmetic sequence adds the same amount each step, so it grows in a straight line. A geometric sequence multiplies by the same amount, so it grows (or shrinks) exponentially. The difference decides whether a total is or , and whether a loop runs times or times.
| Arithmetic | Geometric | |
|---|---|---|
| Rule | add : | multiply by : |
| Example | () | () |
| nth term | ||
| Sum of terms | , quadratic in | , dominated by the last term |
| Shape | straight line | exponential curve |
| In code | i += 2: iterations | i *= 2: iterations |
Formula 1
Jump to any term
The nth term
Worked example. Find the 6th term of . Here , and , so . Check by walking: 2, 6, 18, 54, 162, 486. Another: with and , .
def nth_term(a1, r, n): return a1 * r ** (n - 1)terms = [2]for _ in range(5): terms.append(terms[-1] * 3) # multiply by r each stepprint(terms) # [2, 6, 18, 54, 162, 486]print(nth_term(2, 3, 6)) # 486print(nth_term(3, 2, 6)) # 96print(nth_term(1, 2, 11)) # 1024 = 2**10Fast power
Computing r to the n in O(log n)
The formula needs . Multiplying by itself times is . Binary exponentiation (fast power) reads the exponent in binary instead: square the base each round, and multiply it into the result whenever the current bit is 1. The exponent halves every round, so there are only about rounds.
Squaring instead of repeating
The fast power loop
exp, so the loop runs about times. Python's pow(r, n, m) does this for you, with an optional modulus.Formula 2
Adding the first n terms
Adding terms one by one is . The multiply-and-subtract trick gives a closed form. Write the sum , write underneath, and notice that is the same list shifted one place. Subtract, and everything in the middle cancels.
The multiply-and-subtract trick
The finite sum
- 1Write S1 + 2 + 4 + 8 + 16 + 32
- 2Multiply by r2S = 2 + 4 + 8 + 16 + 32 + 64
- 3Subtract2S - S = 64 - 1, the middle cancels
- 4SolveS = 63 = 2^6 - 1
The identity to memorise
1 + 2 + 4 + ... + 2^k = 2^(k+1) - 1
Powers of two
You can see it in binary too: is 111111, and adding 1 gives 1000000 , so the sum is . Whenever work doubles from one level to the next, the last level is bigger than all the earlier levels combined.
Where the identity shows up
Binary tree nodes
A full tree of height has nodes, and about half are leaves.
Recursion calls
A function that calls itself twice for levels makes calls in total.
Array resizes
Doubling from 1 to copies elements.
Bit masks
(1 << (k + 1)) - 1is ones in binary, the same number.
Formula 3
Infinite series that add up
When the terms shrink towards 0, and in the sum formula. So infinitely many terms add up to a finite number: . Each new term covers exactly half of the gap that is left, so the total creeps towards 2 and never passes it.
The infinite sum
Does the infinite sum exist?
Halving
Binary search is a shrinking sequence
Binary search keeps half of the range after every comparison: . That is a geometric sequence with and . The number of steps is the number of terms before it reaches 1.
Counting the halvings
| Items | Halvings to reach 1 | Worst-case comparisons | Linear search |
|---|---|---|---|
| 64 | 6 | 7 | 64 |
| 1,024 | 10 | 11 | 1,024 |
| 1,000,000 | 19 | 20 | 1,000,000 |
| 1,000,000,000 | 29 | 30 | 1,000,000,000 |
Doubling
Why dynamic array append is amortised O(1)
A Python list or Java ArrayList keeps spare capacity. When it is full, it allocates a bigger block and copies every element across, which costs for that one append. If the capacity doubles, the copy costs over the array's life are : a geometric sequence.
Total copies for n appends
One append
Grow by a factor (x2, x1.5)
- Copy costs : geometric, under .
- Append is amortised .
- Used by Python lists, Java ArrayList, C++ vector.
Grow by a constant (+1, +10)
- Copy costs : arithmetic, about .
- Append becomes on average, in total.
- A classic cause of slow string building.
Exponential time
Doubling recursion is O(2^n)
Naive recursive Fibonacci calls itself twice per call. Level 0 has 1 call, level 1 has 2, level 2 has 4, and level up to : a geometric sequence with . Summing the levels gives the total number of calls.
Calls double at every level
Total calls for n levels
Pattern spotting
Reading complexity from the ratio
Which geometric pattern is this?
i *= 2 reaches in steps; a recursion that doubles its calls per level does work.The complexity connection
O(log n): halving, r = 1/2
Binary search, fast exponentiation, merge sort depth, balanced tree height.
O(2ⁿ): doubling, r = 2
Naive recursion, subset generation, Tower of Hanoi.
Amortised O(1)
Doubling arrays and hash table resizes: a geometric sum under .
O(n) total from shrinking work
Work , as in building a heap or quickselect on average.
Recap
Key takeaways
Key points
- A geometric sequence multiplies by a fixed ratio : .
- The finite sum is , from multiplying by and subtracting; when it is .
- : a doubling series is less than twice its last term.
- When the infinite sum is ; otherwise it diverges.
- Halving (r = 1/2) gives steps; doubling work per level (r = 2) gives .
- Doubling a dynamic array copies under elements in total, so append is amortised .
- Compute large powers with fast exponentiation in , and keep integer sums exact with
//.