BS Artificial Intelligence · Semester 1 · Week 10

Discrete Mathematics for BSAI

Recurrence Relations and Recursive Functions

Dr. Hira Benish
Associate Professor & HoD, Mathematics
PMAI Lab, Mathematics Behind AI

Week 10 · Dr. Hira BenishBegin reading  

01 · Opening Scenario: Tomorrow's Backlog

A support desk starts with 12 requests waiting. At each daily update, five new requests arrive and three are handled. What number will be waiting after the next update? After three updates?

Predict informally: The first update changes 12 to 14, because 12+5−3=14. If the same numbers apply again, the backlog becomes 16, then 18. Our main question is: How can a rule for the next value describe a whole sequence?

We will express the same reasoning mathematically, check several steps, and then consider what the system is entitled to predict.

02 · Learning Objectives and Three-Hour Guide

By the end of Week 10, you should be able to read an initial condition and a one-step recurrence; calculate terms by repeated substitution; compare a simple recurrence with an explicit rule; trace a small recursive definition; distinguish recursion from iteration; and state the assumptions behind a growth model.

Class timeEssential work
55 minBacklog scenario, initial value, recurrence model
50 minRepeated substitution, term table, explicit comparison
45 minRecursive function and a small hand trace
30 minPass the Value, visualization, exit check

Classroom essentials Sections 01–10 and Practice 1–5. Optional self-study The Colab checks and Practice 6–7. Work out the mathematics before running code.

03 · The Initial Condition Anchors the Rule

A recurrence describes one value using a previous value. To obtain actual numbers, we also need a starting value, called an initial condition. We label the starting backlog B₀=12. Here B₀ means the backlog before any daily update, not the count on a mysterious Day 0.

Updates completed nMeaningBacklog Bₙ
0Starting snapshot12
1After one update14
2After two updates16
3After three updates18
Quick check: If the starting backlog were 20 with the same daily change, the next value would be 22. The update rule by itself does not determine the starting backlog.

04 · One Step at a Time

The desk gains five requests and removes three at each update. Its net change is +2. Therefore, for every update we choose to model, the next backlog is the current backlog plus 2:

B₀=12, and Bₙ₊₁=Bₙ+2 for n≥0.

The subscript n+1 means “after one more update.” Read the second line in words: take the backlog after n updates and add two to obtain the backlog after n+1 updates. This is a one-step recurrence relation.

What the two lines do

The initial line gives B₀=12. The recurrence gives B₁=B₀+2=14. Applying the same recurrence again gives B₂=B₁+2=16. Neither line is complete on its own for calculating this particular sequence.

05 · Repeated Substitution Builds the Terms

To find a later value, repeatedly replace “previous backlog” with the value already found. Keep the index beside every result so the number of updates remains clear.

B₀=12 (starting snapshot)

B₁=B₀+2=12+2=14

B₂=B₁+2=14+2=16

B₃=B₂+2=16+2=18

B₄=B₃+2=18+2=20

Each row uses exactly one earlier result. A term table is especially useful when the update depends on the current value and no simple direct formula is apparent.

Backlog values after zero to four updates: 12, 14, 16, 18, 20 1214161820 B₀B₁B₂B₃B₄ +2+2+2+2
Figure 1. Every arrow represents one update, so the index increases by one each time.

06 · Next-Step Rule Versus Direct Term Rule

From Week 9, an explicit rule calculates a term directly from its index. In the backlog model, each of the n updates adds 2 to the starting 12, giving Bₙ=12+2n for n≥0.

FormHow to find B₄What it emphasizes
Recurrence: B₀=12; Bₙ₊₁=Bₙ+212 → 14 → 16 → 18 → 20How one update changes the current value
Explicit: Bₙ=12+2nB₄=12+2(4)=20A value from its index directly

These two descriptions agree for this stated model. To compare them, check both the initial value and the update: the direct rule gives B₀=12, and Bₙ₊₁−Bₙ=[12+2(n+1)]−[12+2n]=2. This short check explains why the same terms appear; a few matching entries alone would be weaker evidence for a general claim.

Quick check: The list 3,5,7 in Week 9 started at a₁=3. Here we start at B₀=12. Always read the index and starting value before substituting.

07 · Two Other Simple Models

The structure “initial value + update” applies beyond backlogs. A balance starts at 20 units and receives 5 units each step: A₀=20, Aₙ₊₁=Aₙ+5. Its first values are 20,25,30,35. A simulated count starts at 2 and doubles each step: W₀=2, Wₙ₊₁=2Wₙ. Its first values are 2,4,8,16.

ModelWhat changes each step?First four terms, n=0..3
Backlog BAdd 212, 14, 16, 18
Balance AAdd 520, 25, 30, 35
Simulated count WMultiply by 22, 4, 8, 16

Adding a fixed amount gives a linear term pattern in these examples; multiplying by a fixed factor gives a geometric pattern. The doubling example is only a stipulated simulation. It does not assert that real requests, savings, or people double indefinitely.

08 · Pass the Value

Predict → Test → Explain Select a model, read its initial value and update, and predict the next term before revealing it. Repeat to build a term table. The interactive version stops after five updates, keeping every case small enough to trace by hand.

Which value comes next?

B₀=12; Bₙ₊₁=Bₙ+2.

Start with the initial value. Apply one update.

Trace: no updates yet.
Discuss: A partner says W₃=12 because “the update adds two.” Locate the mistaken operation and give the correct third-update value.

09 · What a System Can and Cannot Predict

A support dashboard can use B₀=12 and Bₙ₊₁=Bₙ+2 to display a modelled backlog of B₄=20 after four updates. The input assumptions are explicit: every step has five arrivals and three handled requests, counts are accurate, and the same rule remains in force.

If actual arrivals or completions vary, that recurrence needs different inputs or an updated rule. For example, if only one request arrives in a later step and three are handled, the net change for that step would be −2, not +2. In this chapter all backlog values are positive, so we do not need a separate rule for what happens when the queue empties.

Scenario → Mathematics → System

Scenario: requests wait and change daily. Mathematics: an initial backlog and one update rule generate a sequence. System: the dashboard reports values conditional on those assumptions, not guaranteed observations of future days.

10 · A Recursive Function Says the Same Thing

A recursive definition states a starting case and describes later outputs using an earlier output of the same function. Let f(n) be the modelled backlog after n updates:

f(0)=12; for n≥1, f(n)=f(n−1)+2.

To calculate f(3), we need f(2); that needs f(1); that needs f(0). Then work back from the known starting case:

f(3) → f(2) → f(1) → f(0)=12

f(1)=12+2=14, f(2)=14+2=16, f(3)=16+2=18.

The initial case is also the stopping point for this calculation. Without it, we keep asking for an earlier value and never reach a number. This is the same sequence as Bₙ, written as a function of n.

Quick check: If g(0)=3 and g(n)=g(n−1)+4 for n≥1, then g(2)=11, not 7. Two updates have occurred.

11 · Optional Colab: Iterate, Then Trace Recursion

Self-study · mathematics first Complete the backlog term table and trace f(3) on paper. Python is a check of those answers. We use a list and loop already seen in Week 9, then a short function.

1 · Reuse a loop to generate terms

Start with 12. The list initially stores B₀. In range(5), Python supplies the integers 0,1,2,3,4: one pass for each of five updates. append puts the newly calculated value at the end of the list; values[-1] reads its last stored value.

values = [12]
for step in range(5):
    next_value = values[-1] + 2
    values.append(next_value)
print(values)

Predict [12, 14, 16, 18, 20, 22]. The list has six terms: the initial term and five updates. This loop is iteration: it repeats an update using the most recent value.

2 · State a recursive function

The name backlog stands for the function f. def defines it; if n == 0 tests the stopping case; return gives the result back. Otherwise the function asks for the preceding result and adds 2.

def backlog(n):
    if n == 0:
        return 12
    return backlog(n - 1) + 2

print(backlog(3))

Predict 18. Trace the request as backlog(3) → backlog(2) → backlog(1) → backlog(0), then return 12, 14, 16, 18. Use only small nonnegative whole-number inputs here; the definition has no stopping case for negative input.

3 · Explain the comparison

Both snippets use the same starting value and +2 update, so their small outputs agree. The loop moves forward from a stored value; the function asks for smaller input until it reaches its stopping case. Write one sentence explaining which mathematical line is represented by return 12 and which by return backlog(n - 1) + 2.

12 · Practice

Show the starting value and at least two intermediate terms. Selected solutions follow at the end.

  1. u₀=7, uₙ₊₁=uₙ+3 for n≥0. Find u₁,u₂,u₃,u₄ and a simple explicit rule.
  2. v₀=3, vₙ₊₁=2vₙ. Calculate v₁,v₂,v₃. Explain why v₃ is not 3+3(2).
  3. A balance starts at 20 units and increases by 5 units each step. Write its initial condition and one-step recurrence using Aₙ. Find A₄.
  4. Two sequences share the rule xₙ₊₁=xₙ+4. One starts at x₀=1, the other at x₀=9. Find each x₂. What does this show?
  5. For f(0)=5 and f(n)=f(n−1)+2 for n≥1, trace f(3) in both directions: calls toward the stopping case, then numerical results back.
  6. A learner claims Bₙ=12+2n matches B₀=12, Bₙ₊₁=Bₙ+2 because it produces the same value for n=3. Give a stronger two-part check.
  7. A help desk really handles four requests rather than three on the second update only. It starts at 12; five arrive each update, and three are handled on all other updates. Find the actual backlog after three updates and compare it with the constant-change model's prediction. State the assumption that failed.
Exit check: Write an initial condition and a recurrence for “start at 4 and subtract 1 at each update.” Compute the value after two updates and say how an iterative calculation differs from a recursive call.

13 · Common Mistakes

Tempting moveRepair
Use an update rule without a starting value.Specify B₀ (or another starting index); different starts give different sequences.
Call B₃ “the backlog on Day 3” without defining the index.Here B₃ means after three completed updates.
Multiply when the recurrence adds, or add when it multiplies.Read the operation before calculating every next term.
Count the initial term as the first update.n=0 is the starting snapshot; n=1 is after one update.
Write a recursive definition without a stopping case.State f(0), then calculate f(n) from f(n−1).
Treat a modelled future value as an observed fact.Name the assumption that the same update applies at each step.

14 · Summary

  • An initial condition gives the first value; a recurrence tells how to obtain the next value from an earlier one.
  • Repeated substitution builds a term table one update at a time.
  • A simple explicit rule can calculate directly from the index; check its initial value and update when comparing it with a recurrence.
  • A recursive function includes a starting case and an earlier call. Iteration repeatedly updates a current value.
  • A prediction from a growth model depends on its stated assumptions.

15 · Visual Concept Map

Initial condition and one-step rule produce terms; repeated updates can be calculated by iteration or a recursive function and compared with an explicit rule INITIAL CONDITIONONE-STEP RULETERM SEQUENCEITERATIONRECURSIVE FUNCTION B₀=12Bₙ₊₁=Bₙ+212, 14, 16, 18, …move forward from B₀ask for the previous result
The recurrence supplies the mathematical rule; two small computations can trace the same values.

16 · Looking Ahead

Week 11 asks how many choices or arrangements are possible. We will decide when to add cases, when to multiply stages, and why the order of selected objects can matter. The careful treatment of steps and assumptions from this week remains useful.

Selected Solutions

Pass the Value

Backlog: 12,14,16,18,20; balance: 20,25,30,35,40; doubling: 2,4,8,16,32, all indexed n=0,…,4. The index increases by one per update. Without the initial value, the update alone does not select a unique sequence. In the discussion, W₃=16 because three doublings take 2 to 4 to 8 to 16.

1 · Additive recurrence

u₁=10,u₂=13,u₃=16,u₄=19; after n updates, uₙ=7+3n.

2 · Doubling recurrence

v₁=6,v₂=12,v₃=24. Each update multiplies the preceding term by 2; adding 2 three times uses a different rule.

3 · Balance

A₀=20, Aₙ₊₁=Aₙ+5 for n≥0; values 20,25,30,35,40, so A₄=40.

4 · Why the start matters

Starting at 1 gives 1,5,9, so x₂=9. Starting at 9 gives 9,13,17, so x₂=17. Same update, different initial conditions.

5 · Recursive trace

Calls: f(3)→f(2)→f(1)→f(0). Results: f(0)=5, f(1)=7, f(2)=9, f(3)=11.

6 · Compare descriptions

Check B₀=12+2(0)=12. Then (12+2(n+1))−(12+2n)=2 for each n≥0, matching the update.

7 · Changed second update

Actual backlog: 12→14 after the first update, 14+5−4=15 after the second, and 15+5−3=17 after the third. Constant-change model predicts B₃=18. The assumption of three handled requests at every step failed.

Exit check

c₀=4, cₙ₊₁=cₙ−1 for n≥0; c₂=2. Iteration updates a current value forward; a recursive call requests a previous result until a starting case is reached.