An algorithm is a clear, step-by-step list of instructions that tells you exactly what to do. Think of it like a recipe: "Add flour, mix, then bake." In math, algorithms help us generate sequences and model patterns using simple rules. Pseudocode is a way of writing algorithms using everyday language mixed with code-like structure — it's meant to be read by humans, not computers.
Loops are the key tool in algorithms for generating patterns. A loop repeats a set of instructions multiple times. For example, "repeat 10 times: add 5 to x" generates 10 terms of a linear pattern. When a loop adds a fixed number each time, it models a linear pattern (constant difference). When a loop multiplies by a fixed factor each time, it models an exponential pattern (constant ratio). Mixed updates, like "add 3 then multiply by 2," produce non-linear patterns that grow faster than either alone.
Why does this matter in real life? Algorithms are everywhere. Budgeting uses linear updates: "Add $50 to savings each month." Investing uses exponential updates: "Account grows by 0.8% each month." Science and technology use both: sensor readings might be scaled by a fixed factor (exponential) or adjusted by a fixed offset (linear). Understanding which type of update to use helps you model situations accurately.
In this lesson, you'll learn to write, trace, and interpret simple algorithms that match the mathematical rules you've been studying. You'll see how loops in code directly connect to the patterns you've been analyzing in tables and equations.
Linear loop — "start at 2, add 3 each step"
x = 2
print x
repeat 5 times:
x = x + 3
print x
| Term # | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Value | 2 | 5 | 8 | 11 | 14 | 17 |
Exponential loop — "start at 500, multiply by 1.2 each step"
x = 500
print x
repeat 4 times:
x = x * 1.2
print x
| Term # | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Value | 500 | 600 | 720 | 864 | 1036.8 |