7. Sequences and Recursion
CAUTION - CHAPTER UNDER CONSTRUCTION!
This chapter was last updated on March 3, 2025.
Contents locked until 11:59 p.m. Pacific Standard Time on May 23, 2025.
Sequences are functions with domain a nonempty subset of the natural numbers. That is, sequences are ordered lists of objects indexed by some or all of the natural numbers. The indexed objects in the list are called the terms of the sequence and may be any kind of object - numbers, sets, functions, strings, steps of a proof, steps of an algorithm, etc.
Recursion is a process that you can use to define an object, compute a value, or describe the construction of an object or set of objects, by using a sequence of steps where each step after the initial step refers to one or more previously completed steps.
Key terms and concepts covered in this chapter:
-
Sequences
-
Recursive mathematical definitions
-
Recursive definitions of sequences and functions
-
Factorials
-
Arithmetic and geometric progressions
-
The Fibonacci sequence (also called the Fibonacci numbers)
-
Other sequences and functions
-
-
Recursive definitions of sets of objects (e.g., rooted trees, valid Java identifiers)
-
The "Towers of Hanoi" game
-
-
Recurrence relations
-
Solving recurrence relations
-
7.1. Sequences
A sequence is a function \(s\) from a nonempty subset of the natural numbers \(\mathbb{N} = \{ 0, 1, 2, 3 \ldots \}\) to a set \(C.\) That is, the domain of the sequence is some set of nonnegative integers, and the codomain can be any set. Each "input" value of \(n\) in the domain is called an index. The "outputs" of the sequence are called the terms of the sequence, and are usually denoted by \(s_{n},\) which is usually used instead of the function notation \(s(n),\) but the meaning is the same: The output value that corresponds to the input \(n.\)
7.1.1. Sequences of Numbers
Two common ways to describe or define a sequence of numbers are
-
a single formula, called a closed form for the sequence, that can be used to compute a term from the value of the index \(n,\) or
-
a recursive rule that includes
-
stating the values of the first few terms of the sequence, called the initial value(s) of the sequence, and
-
a recurrence relation that describes how the \(n\)th term of the sequence \(a_{n}\) can be computed using one or more terms that have index less than \(n.\)
-
In this subsection, several examples of sequences of numbers are presented. You may have seen some of these sequences in your previous mathematics experience but others may be new to you.
An arithmetic sequence is a sequence of numbers generated by a linear expression.
A geometric sequence is a sequence of numbers generated by an exponential expression.
The factorial is usually defined using a recurrence relation, but with its own notation that does not use a subscript for the index.
The next sequence is the very famous
Fibonacci numbers,
named for the Italian mathematician Fibonacci who was also known as Leonardo of Pisa. However, this sequence and its properties were known and discussed by Indian poets and mathematicians such as
Pingala,
Virahanka,
and
Hemachandra
before Fibonacci was born. The sequence became known to Europeans when Fibonacci used the sequence in his 1202 book
Liber Abaci
to solve a counting problem that involves
breeding pairs of rabbits
The book
Liber Abaci
("Book of Calculation") is credited with popularizing the use of the base-ten Hindu-Arabic numeral system in Europe, too.
7.1.2. Non-numerical Sequences
As mentioned above, the terms of a sequence can be any object. Here are some examples.
The ordered list of steps used in an algorithm is a sequence.
7.2. Recursion
A recursive definition of a class of objects consists of two steps.
Basis Step |
Specify the foundational (usually, the simplest) objects in the class of objects. |
Recursion |
Describe how to build new objects from one or more already-constructed objects in the class of objects. |
7.2.1. Recursively-Defined Structures
For some mathematical objects, it is easier to describe the construction of the objects using a recursive definition.
You may recall that well-formed formulae were defined in the Logic chapter using a recursive definition. We formalize that definition here.
In the next example, we describe how to construct rooted trees, a type of graph.
7.2.2. Recursively-Defined Functions
A recursively defined function has two parts:
-
Basis Step: Specify the value of the function at zero
-
Recursion Step: Give a rule for finding its value at an integer from its value at smaller integers.
This is similar to a recurrence relation, but using function notation.
7.3. Solving Recurrence Relations
Recall from earlier in this chapter that a recurrence relation is used to recursively define a sequence of numbers, based on one or more initial conditions, that is, the value(s) of the lowest-indexed term(s).
The phrase "solving a recurrence relation" means finding a closed form that defines the same sequence as the recurrence relation.
There are techniques used to solve certain classes of recurrence relations. For now, we will focus on only one case, the class of second-order linear homogeneous recurrence relations.
7.4. Towers Of Hanoi

The
Towers of Hanoi
is a game that was introduced and sold by the French mathematician Édouard Lucas in the 1880s. Lucas stated that the game is
"professedly of Indo-Chinese origin"
but it seems that Lucas invented this story
to market the game.
Image credit:
"PSM V26 D464 The tower of hanoi.jpg".
This work is in the public domain in its country of origin and other countries and areas where the copyright term is the author’s life plus 70 years or fewer.
At the start of the game, a set of disks of different radii are stacked on a single peg to form a "tower." The disks are stacked so that the radii of the disks decrease as you move up the stack. There are also two empty pegs. The game is won by moving the stack of disks from the original peg to another peg using the following rules
-
Only one disk can be moved at a time.
-
The disk at the top of a stack can be moved to the top of another stack or on to an empty peg.
-
A disk can never be placed on top of a disk that has a smaller radius.
The Towers of Hanoi can be used to explore recursive algorithms, complexity of algorithms, and recurrence relations, based on the following questions.
-
What is the minimal number of moves needed to win the game when there is 1 disk? 2 disks? 3 disks? \(n\) disks?
-
What relationship (if any) is there between the minimal number of moves needed to win an \(n\)-disk game and the minimal number of moves needed to win an \((n-1)\)-disk game?
MORE TO COME!