The Central Idea

Suppose a sequence is defined by

\[ a_1=4,\qquad a_n=a_{n-1}+3. \]

The recurrence tells us the mathematical relationship.

An algorithm describes the procedure:

  1. start with \(4\);
  2. add \(3\);
  3. record the new value;
  4. repeat until the desired term is reached.

This generates

\[ 4,\ 7,\ 10,\ 13,\ 16,\ldots \]

The recurrence is the rule; the iteration is the repeated execution of that rule.

What Is Iteration?

Iteration is the repeated application of a procedure or transformation.

If

\[ a_n=f(a_{n-1}), \]

then the function \(f\) is applied again and again:

\[ a_1 \longrightarrow a_2 \longrightarrow a_3 \longrightarrow a_4 \longrightarrow\cdots \]

Each new output becomes input for the next step.

What Is a Recurrence Algorithm?

A recurrence algorithm is a step-by-step procedure for generating terms from a recurrence relation.

A recurrence algorithm usually specifies:

Mathematical Rule Versus Algorithm

Consider

\[ a_1=2,\qquad a_n=2a_{n-1}+1. \]

The recurrence is concise mathematical notation.

An algorithmic description is:

  1. set the current value equal to \(2\);
  2. multiply the current value by \(2\);
  3. add \(1\);
  4. replace the old value with the new value;
  5. repeat as needed.

Both describe the same process from different viewpoints.

The Idea of State

The state is the information that must be remembered from one step to the next.

For

\[ a_n=3a_{n-1}-2, \]

only the most recent term is needed.

Thus the state may consist of a single value:

\[ \boxed{\text{state}=a_{n-1}}. \]

State for a Second-Order Recurrence

For

\[ a_n=a_{n-1}+a_{n-2}, \]

the next term depends on two previous terms.

Therefore, the state must remember both:

\[ \boxed{ \text{state}=(a_{n-2},a_{n-1}) }. \]

After calculating \(a_n\), the state shifts forward.

State Update

A state update replaces the current stored information with the information needed for the next iteration.

For Fibonacci-type iteration,

\[ (a_{n-2},a_{n-1}) \]

becomes

\[ \boxed{ (a_{n-1},a_{n-2}+a_{n-1}) }. \]

The new pair contains the two most recent terms.

Example: Iterating a First-Order Recurrence

Let

\[ a_0=1 \]

and

\[ a_{n+1}=2a_n+3. \]

Then

\[ a_1=2(1)+3=5, \] \[ a_2=2(5)+3=13, \] \[ a_3=2(13)+3=29, \] \[ a_4=2(29)+3=61. \]

Therefore,

\[ \boxed{1,\ 5,\ 13,\ 29,\ 61,\ldots}. \]

Indexing the Update Correctly

The recurrence

\[ a_{n+1}=2a_n+3 \]

says that the value at the next index is calculated from the current one.

If \(n=0\), then

\[ a_1=2a_0+3. \]

If \(n=1\), then

\[ a_2=2a_1+3. \]

Careful index tracking prevents off-by-one errors.

Loops

In computational thinking, repeated execution is often organized as a loop.

A loop repeats an update until a specified condition is satisfied.

Conceptually:

\[ \boxed{ \text{initialize} \longrightarrow \text{update} \longrightarrow \text{check} \longrightarrow \text{repeat or stop} }. \]

Count-Controlled Iteration

Sometimes the number of repetitions is known in advance.

For example, to calculate \(a_{10}\) from

\[ a_1=4,\qquad a_n=a_{n-1}+3, \]

we need

\[ 10-1=9 \]

updates.

This is a count-controlled iteration.

Condition-Controlled Iteration

Sometimes we do not know in advance how many repetitions will be needed.

Suppose

\[ a_0=1,\qquad a_{n+1}=2a_n \]

and we want the first term exceeding \(1000\).

We repeatedly double until

\[ a_n>1000. \]

The stopping rule depends on a condition rather than a predetermined number of steps.

Stopping Conditions

A stopping condition tells an algorithm when iteration is complete.

Common stopping conditions include:

Example: Stop at a Threshold

Let

\[ a_0=5,\qquad a_{n+1}=1.5a_n. \]

Find the first term greater than \(20\).

Iterate:

\[ a_0=5, \] \[ a_1=7.5, \] \[ a_2=11.25, \] \[ a_3=16.875, \] \[ a_4=25.3125. \]

Therefore, the first term exceeding \(20\) is

\[ \boxed{a_4=25.3125}. \]

Iteration Tables

A table helps track the state of an iterative process.

For

\[ a_0=2,\qquad a_{n+1}=3a_n-1, \]

we may record:

Iteration \(n\) Current Value \(a_n\) Next Calculation
\(0\)\(2\)\(3(2)-1=5\)
\(1\)\(5\)\(3(5)-1=14\)
\(2\)\(14\)\(3(14)-1=41\)
\(3\)\(41\)\(3(41)-1=122\)

Pseudocode

Pseudocode describes an algorithm in structured language without requiring the exact syntax of a programming language.

For

\[ a_1=4,\qquad a_n=a_{n-1}+3, \]

pseudocode might say:

value = 4
repeat 9 times:
    value = value + 3
output value

After nine updates, the output is \(a_{10}\).

Pseudocode Is a Mathematical Representation

Pseudocode is useful because it makes procedural structure explicit.

A recurrence answers:

\[ \text{How are consecutive states related?} \]

Pseudocode answers:

\[ \text{What exact steps should be executed?} \]

Both are legitimate representations of the same mathematical process.

From an Explicit Formula to an Algorithm

Not every sequence requires recurrence.

Suppose

\[ a_n=3n^2+1. \]

To generate the first ten terms, an algorithm can loop over

\[ n=1,2,\ldots,10 \]

and calculate

\[ 3n^2+1 \]

independently at each step.

This is iterative computation without recursive dependence.

Direct Computation Versus Sequential Computation

An explicit formula often allows direct computation.

For

\[ a_n=5n+2, \]

we can calculate \(a_{1000}\) immediately.

A recurrence such as

\[ a_n=a_{n-1}+5 \]

naturally suggests sequential computation, building terms one by one.

Equivalent Algorithms Can Have Different Efficiency

Suppose an arithmetic sequence satisfies

\[ a_1=3,\qquad a_n=a_{n-1}+7. \]

To find \(a_{1000000}\), repeated iteration requires many additions.

But the explicit formula

\[ a_n=3+7(n-1) \]

gives the same result in one direct calculation.

Mathematically equivalent methods can therefore have very different computational costs.

Algorithmic Efficiency

Efficiency concerns the resources an algorithm uses, such as:

A mathematically correct algorithm may still be inefficient.

Fibonacci by Iteration

Consider

\[ F_0=0,\qquad F_1=1,\qquad F_n=F_{n-1}+F_{n-2}. \]

To generate terms efficiently, we only need to store the two most recent Fibonacci numbers.

The state update is

\[ (x,y) \longrightarrow (y,x+y). \]

Fibonacci Iteration Example

Start with

\[ (0,1). \]

Repeated updates give

\[ (0,1) \longrightarrow (1,1) \longrightarrow (1,2) \longrightarrow (2,3) \longrightarrow (3,5) \longrightarrow (5,8). \]

Each state contains two consecutive Fibonacci numbers.

Pseudocode for Fibonacci Iteration

x = 0
y = 1

repeat:
    next = x + y
    x = y
    y = next

The temporary value

next

preserves the new sum before the older state values are shifted.

Why Update Order Matters

Suppose we begin with

\[ x=3,\qquad y=5. \]

The correct next Fibonacci-type state is

\[ (5,8). \]

If we first overwrite

\[ x=y, \]

then \(x\) becomes \(5\).

If we then calculate

\[ y=x+y, \]

we obtain \(10\), not \(8\).

The old value of \(x\) was lost too early.

Temporary Storage

A temporary variable preserves information during a state update.

Conceptually:

  1. calculate the new value;
  2. store it temporarily;
  3. shift the old values;
  4. place the temporary value into the new state.

This idea appears throughout numerical algorithms.

Recursive Algorithms

A procedure can also call itself to solve a smaller instance of the same problem.

For example, Fibonacci numbers can be described recursively as:

\[ F_n= \begin{cases} 0,&n=0,\\ 1,&n=1,\\ F_{n-1}+F_{n-2},&n\geq2. \end{cases} \]

A recursive algorithm mirrors this definition by requesting the values of \(F_{n-1}\) and \(F_{n-2}\).

Base Cases

A recursive algorithm needs base cases that can be answered directly.

For Fibonacci numbers, the base cases are

\[ F_0=0 \]

and

\[ F_1=1. \]

Without base cases, recursive calls would continue indefinitely.

Recursive Versus Iterative Fibonacci Computation

A direct recursive implementation closely resembles the mathematical definition.

However, a naive recursive method may repeatedly recompute the same smaller Fibonacci numbers.

Iteration avoids this repeated work by storing the current state.

Thus mathematical elegance and computational efficiency do not always point to the same implementation.

Repeated Work in Naive Recursion

To calculate

\[ F_5, \]

naive recursion asks for

\[ F_4 \]

and

\[ F_3. \]

But calculating \(F_4\) itself also requires \(F_3\).

The same subproblem is therefore calculated more than once.

Memoization

Memoization stores previously calculated results so they do not need to be recomputed.

For Fibonacci numbers, once \(F_k\) has been found, it can be saved and reused.

This turns repeated recursive work into lookup.

Memoization is one bridge between recursive definitions and efficient algorithm design.

Dynamic Programming

Dynamic programming solves larger problems by systematically building from solutions to smaller subproblems.

A Fibonacci table

\[ F_0,\ F_1,\ F_2,\ldots,F_n \]

is a simple example.

Each stored value supports later calculations.

Iteration and Function Composition

If

\[ a_{n+1}=f(a_n), \]

then

\[ a_1=f(a_0), \] \[ a_2=f(f(a_0)), \]

and

\[ a_3=f(f(f(a_0))). \]

Repeated iteration is repeated function composition.

Iterates

The notation

\[ f^{\circ n} \]

can be used to mean \(n\)-fold composition of \(f\) with itself.

Then a first-order iteration may be written

\[ \boxed{ a_n=f^{\circ n}(a_0) } \]

when the indexing and definition are compatible.

The composition symbol helps distinguish iteration from ordinary exponentiation.

Example: Repeated Affine Transformation

Let

\[ f(x)=2x+1 \]

and

\[ a_0=0. \]

Then

\[ a_{n+1}=f(a_n). \]

Iterating:

\[ a_1=1, \] \[ a_2=3, \] \[ a_3=7, \] \[ a_4=15. \]

Therefore,

\[ \boxed{0,\ 1,\ 3,\ 7,\ 15,\ldots}. \]

Fixed Points

A fixed point of an iteration

\[ a_{n+1}=f(a_n) \]

is a value \(L\) satisfying

\[ \boxed{f(L)=L}. \]

If an iteration reaches a fixed point exactly, every later term remains there.

Example: Finding a Fixed Point

Consider

\[ a_{n+1}=\frac12a_n+3. \]

A fixed point \(L\) satisfies

\[ L=\frac12L+3. \]

Therefore,

\[ \frac12L=3 \]

and

\[ \boxed{L=6}. \]

Iteration Toward a Fixed Point

Let

\[ a_0=0,\qquad a_{n+1}=\frac12a_n+3. \]

Then

\[ a_1=3, \] \[ a_2=4.5, \] \[ a_3=5.25, \] \[ a_4=5.625. \]

The values move toward

\[ 6. \]

This gives an early example of iterative convergence.

Tolerance-Based Stopping

Numerical algorithms often stop when successive values are sufficiently close.

For example, one might stop when

\[ \boxed{ |a_{n+1}-a_n|<0.001 }. \]

The number \(0.001\) is a tolerance.

A smaller tolerance demands closer agreement before stopping.

Approximation and Iteration

Iteration is especially useful when an exact answer is difficult to obtain directly.

An algorithm may produce

\[ a_1,\ a_2,\ a_3,\ldots \]

that increasingly approximate a desired value.

The algorithm stops when the approximation is accurate enough for the intended purpose.

Newton-Type Iteration

An important later example is Newton's method.

For solving

\[ f(x)=0, \]

the iteration is

\[ \boxed{ x_{n+1} = x_n-\frac{f(x_n)}{f'(x_n)} }. \]

Each approximation is calculated from the previous one.

This is a more advanced recurrence algorithm, but its structure is the same idea developed here.

Algorithms Can Fail to Stop

A stopping condition must actually be reachable.

Suppose

\[ a_0=1,\qquad a_{n+1}=a_n+1 \]

and the algorithm is instructed to stop when

\[ a_n=1.5. \]

The sequence contains only integers

\[ 1,2,3,4,\ldots \]

so the stopping condition will never be met.

Infinite Loops

A procedure that continues indefinitely because its stopping condition is never satisfied is called an infinite loop.

Preventing unintended infinite loops requires checking:

Exact Equality Can Be a Poor Numerical Stopping Test

In approximate numerical computation, a value may approach a target without ever matching it exactly.

Instead of requiring

\[ a_n=L, \]

it may be more practical to require

\[ |a_n-L|<\varepsilon \]

for a chosen tolerance \(\varepsilon>0\).

Rounding Error

Repeated calculations with decimal approximations can accumulate rounding error.

An iterative algorithm may therefore produce values that differ slightly from exact mathematical values.

Good numerical practice distinguishes:

Verification by Independent Calculation

An algorithm can often be checked against another representation.

For an arithmetic sequence,

\[ a_1=5,\qquad a_n=a_{n-1}+4, \]

an iterative calculation of \(a_{20}\) can be checked using

\[ a_n=5+4(n-1). \]

Independent methods provide a strong error check.

Verification with Invariants

An invariant is a property that remains true throughout an algorithm.

For example, if a recurrence always generates even numbers, then obtaining an odd value signals an error.

Invariants can help verify long iterative computations without checking every detail separately.

Example: Parity as an Invariant

Let

\[ a_0=2 \]

and

\[ a_{n+1}=2a_n+4. \]

If \(a_n\) is even, then

\[ 2a_n \]

is even, and adding \(4\) preserves evenness.

Therefore, every term must be even.

Iteration and Tables

An algorithm can be represented as a table of states.

For

\[ x_{n+1}=\frac{x_n+6}{2}, \qquad x_0=10, \]

a table gives:

\(n\) \(x_n\)
\(0\)\(10\)
\(1\)\(8\)
\(2\)\(7\)
\(3\)\(6.5\)
\(4\)\(6.25\)

The table makes the iterative trend visible.

Iteration and Discrete Graphs

The pairs

\[ (n,a_n) \]

can be plotted as a discrete graph.

The graph may reveal:

Periodic Iteration

Some iterative rules cycle through values.

For example, suppose

\[ a_{n+1}=1-a_n \]

with

\[ a_0=0. \]

Then

\[ 0,\ 1,\ 0,\ 1,\ldots \]

repeats with period \(2\).

Divergent Iteration

Consider

\[ a_{n+1}=2a_n \]

with

\[ a_0=1. \]

Then

\[ 1,\ 2,\ 4,\ 8,\ 16,\ldots \]

grows without bound.

Not every iteration approaches a stable value.

Iteration Can Depend on the Index

Some recurrence algorithms use both the current state and the current index.

For example,

\[ a_1=1,\qquad a_n=a_{n-1}+n. \]

The algorithm must track both:

The state is therefore larger than the sequence value alone.

Algorithm for an Index-Dependent Recurrence

For

\[ a_1=1,\qquad a_n=a_{n-1}+n, \]

a procedure is:

value = 1
for n = 2 through target:
    value = value + n
output value

The loop counter \(n\) is itself part of the computation.

Accumulation Algorithms

Finite sums can also be computed iteratively.

To calculate

\[ S_n=\sum_{k=1}^{n}a_k, \]

initialize

\[ S=0 \]

and repeatedly update

\[ \boxed{S\leftarrow S+a_k}. \]

This is a general accumulation algorithm.

Product Accumulation Algorithms

To calculate

\[ P_n=\prod_{k=1}^{n}a_k, \]

initialize

\[ P=1 \]

and update

\[ \boxed{P\leftarrow Pa_k}. \]

The initial value \(1\) is used because it is the multiplicative identity.

Example: Iterative Factorial Algorithm

Since

\[ n!=1\cdot2\cdot3\cdots n, \]

factorial can be computed iteratively:

product = 1
for k = 1 through n:
    product = product * k
output product

For \(n=5\), the running products are

\[ 1,\ 2,\ 6,\ 24,\ 120. \]

Recursive Factorial

Factorial also has a recursive definition:

\[ 0!=1 \]

and

\[ n!=n(n-1)!. \]

Thus the same mathematical quantity can be implemented recursively or iteratively.

Recursive and Iterative Forms Can Be Equivalent

Consider factorial.

Recursive form:

\[ n!=n(n-1)!. \]

Iterative form:

\[ 1\cdot2\cdot3\cdots n. \]

Both compute the same value but organize the computation differently.

Common Error: Forgetting Initialization

Every iterative recurrence needs a valid starting state.

The rule

\[ a_n=a_{n-1}+3 \]

does not determine a unique sequence without an initial term.

Likewise, an algorithm cannot begin if its state has not been initialized.

Common Error: Off-by-One Iteration

Suppose \(a_1\) is already known and we want \(a_{10}\).

We need

\[ 10-1=9 \]

updates.

Performing ten updates would produce \(a_{11}\).

Common Error: Overwriting State Too Early

In a multi-value recurrence, later calculations may still need an old state value.

Updating one variable before saving the necessary information can change the mathematical recurrence being implemented.

Temporary storage or simultaneous assignment prevents this problem.

Common Error: Using the Wrong Initial Identity

For summation, initialize the accumulator with

\[ 0. \]

For multiplication, initialize with

\[ 1. \]

Starting a product at \(0\) would force every later product to remain zero.

Common Error: Stopping Before Recording the Desired State

An algorithm may test its stopping condition before or after an update.

That choice affects which state is returned.

A correct algorithm must clearly specify whether it stops:

Common Error: Assuming Iteration Must Converge

Repeated application of a rule does not guarantee approach to a limit.

An iteration may:

Long-run behavior must be analyzed rather than assumed.

A Reliable Procedure for Turning a Recurrence into an Algorithm

  1. Identify the initial condition or conditions.
  2. Determine what information must be stored as state.
  3. Translate the recurrence into an update rule.
  4. Determine the correct starting index.
  5. Choose a loop structure.
  6. Specify the stopping condition.
  7. Update state in a safe order.
  8. Record or return the required output.
  9. Check the first few results against hand calculations.

A Reliable Procedure for Checking an Iterative Algorithm

  1. Verify the initialization.
  2. Check one update by hand.
  3. Check the index change.
  4. Confirm that required old values are not overwritten too early.
  5. Verify the stopping condition.
  6. Compare against an explicit formula when one exists.
  7. Check invariants or expected qualitative behavior.
  8. Test simple boundary cases.

Example: Full Algorithmic Workflow

Let

\[ a_0=3,\qquad a_{n+1}=2a_n-1. \]

Find \(a_5\).

The initial state is

\[ a_0=3. \]

Five updates are required:

\[ a_1=2(3)-1=5, \] \[ a_2=2(5)-1=9, \] \[ a_3=2(9)-1=17, \] \[ a_4=2(17)-1=33, \] \[ a_5=2(33)-1=65. \]

Therefore,

\[ \boxed{a_5=65}. \]

Example: Full Fibonacci State Workflow

Use

\[ F_0=0,\qquad F_1=1. \]

Begin with state

\[ (0,1). \]

Update by

\[ (x,y)\longrightarrow(y,x+y). \]

Then

\[ (0,1) \to (1,1) \to (1,2) \to (2,3) \to (3,5) \to (5,8). \]

After five updates, the state contains

\[ \boxed{F_5=5,\qquad F_6=8}. \]

Practice 1: First-Order Iteration

Let

\[ a_0=2,\qquad a_{n+1}=3a_n+1. \]

Find \(a_1,a_2,a_3\).

Practice 2: Count the Updates

A sequence begins at \(a_1\).

How many recurrence updates are required to reach \(a_{25}\)?

Practice 3: State Size

For

\[ a_n=2a_{n-1}+3a_{n-2}, \]

how many previous sequence values must an iterative algorithm retain?

Practice 4: Fibonacci Update

If the current Fibonacci state is

\[ (8,13), \]

what is the next state?

Practice 5: Threshold Stopping

Let

\[ a_0=3,\qquad a_{n+1}=2a_n. \]

Find the first term greater than \(50\).

Practice 6: Accumulator Initialization

What initial value should be used for an accumulator computing

\[ \sum_{k=1}^{n}a_k? \]

What initial value should be used for

\[ \prod_{k=1}^{n}a_k? \]

Practice 7: Fixed Point

Find the fixed point of

\[ a_{n+1}=\frac13a_n+4. \]

Practice 8: Iterative Factorial

Use iterative multiplication to calculate

\[ 6!. \]

Practice 9: Identify the Update Error

A student wants to update the Fibonacci state \((x,y)\) and writes:

x = y
y = x + y

Explain why this may produce the wrong result.

Practice 10: Convergence Assumption

A student says that every recurrence algorithm eventually settles at a fixed value.

Explain the error.

Practice Answers

Practice 1

\[ a_1=3(2)+1=7, \] \[ a_2=3(7)+1=22, \] \[ a_3=3(22)+1=67. \]

Therefore,

\[ \boxed{7,\ 22,\ 67}. \]

Practice 2

Starting from \(a_1\), reaching \(a_{25}\) requires

\[ 25-1=\boxed{24} \]

updates.

Practice 3

The recurrence depends on

\[ a_{n-1} \]

and

\[ a_{n-2}. \]

Therefore, the algorithm must retain

\[ \boxed{2\text{ previous values}}. \]

Practice 4

\[ (8,13) \longrightarrow (13,8+13) \] \[ =\boxed{(13,21)}. \]

Practice 5

\[ a_0=3, \] \[ a_1=6, \] \[ a_2=12, \] \[ a_3=24, \] \[ a_4=48, \] \[ a_5=96. \]

Therefore, the first term greater than \(50\) is

\[ \boxed{a_5=96}. \]

Practice 6

For a sum, use the additive identity:

\[ \boxed{0}. \]

For a product, use the multiplicative identity:

\[ \boxed{1}. \]

Practice 7

Let \(L\) be the fixed point:

\[ L=\frac13L+4. \]

Therefore,

\[ \frac23L=4. \]

Thus,

\[ \boxed{L=6}. \]

Practice 8

\[ 6! = 1\cdot2\cdot3\cdot4\cdot5\cdot6 \] \[ =\boxed{720}. \]

Practice 9

After

x = y

the old value of \(x\) has been lost.

Then

y = x + y

uses the new \(x\) instead of the old one.

A temporary value or simultaneous update is needed.

Practice 10

Iterative sequences may converge, diverge, oscillate, cycle, or behave in other ways.

For example,

\[ a_{n+1}=2a_n,\qquad a_0=1 \]

produces

\[ 1,\ 2,\ 4,\ 8,\ldots \]

which grows without approaching a finite fixed value.

What to Remember

A recurrence relation describes how states are related:

\[ \boxed{ \text{previous state} \longrightarrow \text{next state} }. \]

An algorithm turns that relationship into an executable procedure:

\[ \boxed{ \text{initialize} \longrightarrow \text{update} \longrightarrow \text{check} \longrightarrow \text{repeat or stop} }. \]

Where We Go Next

Recurrence algorithms show how discrete mathematical objects evolve one state at a time. We can now step back and compare the broader behavior of discrete functions and sequence patterns, including what it means for their values to approach a stable number.

The next lesson, Discrete Functions, Patterns, and Introductory Convergence, brings together explicit rules, recurrences, graphs, iteration, and long-run behavior while introducing the basic language of convergence.