Recursive Definitions

A recursive definition describes an object by saying how to build it from smaller instances of itself. Instead of giving a formula for the 50th term of a sequence directly, you state where the sequence starts and how each new term follows from the ones before it. You meet this idea in sequences such as account balances and the Fibonacci numbers, in functions such as the factorial, and in sets such as the strings a program accepts. Recursive definitions are also the objects that proofs by induction are built to reason about.

The two parts of a recursive definition

A recursive definition has two parts:

  • A base case that states one or more values outright.
  • A recursive step that gives every other value in terms of values already defined.

When the object is a sequence, the recursive step is called a recurrence relation. For example:


a0=3,an=2an−1+1for n≥1a_0 = 3, \qquad a_n = 2a_{n-1} + 1 \quad \text{for } n \ge 1


Unwinding it one step at a time gives a1=2(3)+1=7a_1 = 2(3) + 1 = 7, then a2=2(7)+1=15a_2 = 2(7) + 1 = 15 and a3=2(15)+1=31a_3 = 2(15) + 1 = 31. Each new term needs only the term before it, so one base case is enough.


The factorial function is defined the same way: 0!=10! = 1 and n!=n⋅(n−1)!n! = n \cdot (n-1)! for n≥1n \ge 1. Unwinding gives 4!=4⋅3!=4⋅3⋅2!=⋯=244! = 4 \cdot 3! = 4 \cdot 3 \cdot 2! = \cdots = 24.


A recurrence that reaches further back needs more starting values. The Fibonacci numbers satisfy Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2}, which looks two terms back, so the definition must supply two base cases, F0=0F_0 = 0 and F1=1F_1 = 1, and the recursive step applies only for n≥2n \ge 2. With only F0F_0 supplied, F1F_1 remains unspecified. Attempting to extend the recurrence to n=1n = 1 would additionally reference F−1F_{-1}, an input outside the domain.



Recursive and explicit formulas

A recursive definition and an explicit, or closed-form, formula can describe the same sequence. The recursive form matches situations that change step by step, such as a monthly balance or a count of moves; the explicit form is faster when you need a distant term.


Sequence

Recursive definition

Explicit formula

Arithmetic, common difference dd

a0a_0 given, an=an−1+da_n = a_{n-1} + d

an=a0+nda_n = a_0 + nd

Geometric, common ratio rr

a0a_0 given, an=r an−1a_n = r\,a_{n-1}

an=a0rna_n = a_0 r^n

Example above

a0=3a_0 = 3, an=2an−1+1a_n = 2a_{n-1} + 1

an=2n+2−1a_n = 2^{n+2} - 1

Fibonacci

F0=0F_0 = 0, F1=1F_1 = 1, Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2}

Exists, but involves 5\sqrt{5}


You can often guess an explicit formula by listing the first few terms. A guess is only a conjecture until it is shown to satisfy both the base case and the recursive step for every nn; that confirmation is a proof by induction.



Recursively defined sets and functions

Sets can be built the same way. Define SS by:

  1. Base case: 3∈S3 \in S.
  2. Recursive step: if x∈Sx \in S and y∈Sy \in S, then x+y∈Sx + y \in S.
  3. Exclusion rule: nothing is in SS unless it comes from the base case by finitely many recursive steps.

Starting from 3 you get 3+3=63 + 3 = 6, then 3+6=93 + 6 = 9, and so on, so SS is the set of positive multiples of 3. Without the exclusion rule, the set of all positive integers would also satisfy the first two rules, so the definition would not pin down a single set.


Strings work the same way. For an alphabet Σ\Sigma, the set Σ∗\Sigma^* has the base case that the empty string λ\lambda is in Σ∗\Sigma^*, and the recursive step that if w∈Σ∗w \in \Sigma^* and x∈Σx \in \Sigma, then wx∈Σ∗wx \in \Sigma^*, the string ww with the symbol xx appended. For Σ={0,1}\Sigma = \{0, 1\}, one step gives 00 and 11, the next gives 0000, 0101, 1010 and 1111, and so on.


A recursive definition of a function is well defined only if every value traces back to a base case in finitely many steps. The rule h(0)=5h(0) = 5 with h(n)=h(n+1)+2h(n) = h(n+1) + 2 for n≥1n \ge 1 fails: h(1)h(1) needs h(2)h(2), which needs h(3)h(3), and the chain never reaches h(0)h(0). A step does not have to move down by exactly one, though; it only has to move to a smaller input that eventually lands on a base case.

What to remember

  • A recursive definition has a base case and a recursive step; for sequences the step is a recurrence relation.
  • A recurrence that looks back kk terms usually needs kk base values.
  • Check which index the base case uses before computing terms.
  • A recursively defined set needs an exclusion rule so it contains only what the rules build.
  • Every value must reach a base case in finitely many steps.

Example: A savings balance defined recursively

A student opens a savings account with $200. At the end of each month the bank adds 1% interest on the current balance, and then the student deposits another $50. Let BnB_n be the balance in dollars just after the deposit at the end of month nn, with B0B_0 the opening balance.


a) Write a recursive definition of BnB_n, giving both the base case and the recursive step.


Base case: before any month has passed, the balance is the opening deposit, so B0=200B_0 = 200.


Recursive step: adding 1% interest multiplies the previous balance by ________, and the deposit then adds 50 dollars. Because interest is applied before the deposit, that month's 50 dollars earns no interest until the following month. For every month after the start:


Bn=1.01 Bn−1+50for n≥1B_n = 1.01\,B_{n-1} + 50 \quad \text{for } n \ge 1


One base case is enough because each balance depends only on the balance one month earlier.


b) Find the balance after three months, B3B_3, to the nearest cent.


Apply the recursive step three times, starting from the base case and keeping full precision until the end.

  • Month 1: B1=1.01(200)+50=B_1 = 1.01(200) + 50 = ________ dollars.
  • Month 2: B2=1.01(252)+50=B_2 = 1.01(252) + 50 = ________ dollars.
  • Month 3: B3=1.01(304.52)+50=307.5652+50=357.5652B_3 = 1.01(304.52) + 50 = 307.5652 + 50 = 357.5652 dollars.

Rounded to the nearest cent, the balance after three months is $357.57.


c) In which month does the balance first exceed $500?


No explicit formula is needed: keep applying the recursive step from B3=357.5652B_3 = 357.5652 until the balance passes 500. Use the exact intermediate balances in every substitution and round only the reported dollar amounts.

  • Month 4: B4=1.01(357.5652)+50=411.140852B_4 = 1.01(357.5652) + 50 = 411.140852 dollars. Rounded to the nearest cent, this is ________ dollars.
  • Month 5: B5=1.01(411.140852)+50=465.25226052B_5 = 1.01(411.140852) + 50 = 465.25226052 dollars, still below 500. Rounded to the nearest cent, this is ________ dollars.
  • Month 6: B6=1.01(465.25226052)+50=519.9047831252B_6 = 1.01(465.25226052) + 50 = 519.9047831252 dollars, which is above 500. Rounded to the nearest cent, this is 519.90 dollars.

The balance first exceeds $500 at the end of month 6, after that month's deposit.


Check: each month adds the 50-dollar deposit plus about 4 dollars of interest, roughly 54 dollars in total, so rising from about 358 to more than 500 should take three more months after month 3, which agrees.

A sequence is defined recursively by the base case a1=4a_1 = 4 and the recursive step an=an−1+6a_n = a_{n-1} + 6 for n≥2n \ge 2. Work forward from the base case to find the missing terms.


The second term of the sequence is and the fifth term of the sequence is .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Each familiar sequence below has a recursive definition made of a base case and a recursive step. Match each sequence to the recursive definition that generates exactly its terms. Check the first three or four terms of each definition rather than relying on its general shape.

Match each term
A.

a0=1a_0 = 1 and an=n⋅an−1a_n = n \cdot a_{n-1} for n≥1n \ge 1

B.

a1=1a_1 = 1 and an=an−1+2n−1a_n = a_{n-1} + 2n - 1 for n≥2n \ge 2

C.

a1=1a_1 = 1 and an=an−1+2a_n = a_{n-1} + 2 for n≥2n \ge 2

D.

a1=1a_1 = 1 and an=an−1+na_n = a_{n-1} + n for n≥2n \ge 2

E.

a0=1a_0 = 1 and an=2an−1a_n = 2a_{n-1} for n≥1n \ge 1

F.

a0=0a_0 = 0, a1=1a_1 = 1 and an=an−1+an−2a_n = a_{n-1} + a_{n-2} for n≥2n \ge 2

Triangular numbers

Fibonacci numbers

Perfect squares

Powers of 2

Factorials 0!, 1!, 2!, ...

Odd positive integers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A sequence begins 2,6,18,54,…2, 6, 18, 54, \ldots and its first term is labelled a1a_1. Which recursive definition produces exactly this sequence, with every listed term in its correct position?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice