Docsity

Recurrence Relations: Solving Counting Problems with Recursive Functions, Study notes of Linear Algebra

Toggle sidebar
bg1
Jim Lambers
Math 6A
Spring Quarter 2003-04
Lecture 22 Notes
These notes correspond to Section 6.1 in the text.
Recurrence Relations
There are many counting problems for which the techniques we have previously studied are not
useful. In the remaining lectures, we will discuss various advanced techniques for solving such
problems.
As counting problems are concerned with determining the cardinality of various sets, we begin
with the use of recursion to describe sets, and, by extension, compute their cardinalities. The basic
idea is to define a set S(n), whose contents depend on the integer n, in terms of sets of the form
S(k) for some integer k < n. Then |S(n)|is an integer-valued function of nthat is a recursively
defined function, as discussed in the previous lecture.
In this lecture, we will focus on the task of constructing functions recursively that describe the
cardinality of such a set S(n). Then, we will consider the problem of obtaining an explicit definition
of a recursively-defined function, since an explicit definition, while more difficult to obtain, is usually
more efficient to evaluate, especially for large values of n.
In a recursive definition of a function f:A→B, certain initial values of the function must be
defined explicitly, for the basis step of the definition. The recursive step describes how f(x), for
any x∈Athat is not already considered in the basis step, is to be computed using values of f
corresponding to other elements of A. Typically, f(x) is related to the other function values by an
equation, which we now describe precisely.
Definition (Recurrence Relation) Let {an}∞
n=0 be a sequence. A recurrence relation is an equa-
tion that relates anto an−1,an−2,. . .,an−k, for some fixed integer kand each n≥n0, where n0
is a nonnegative integer. A sequence whose terms satisfy a recurrence relation is called a solution
of the recurrence relation.
Example The sequence of Fibonacci numbers {fn}∞
n=0, introduced in the previous lecture, is defined
by the simple recurrence relation
fn=fn−1+fn−2, n ≥2,
with f0= 0 and f1= 1. 2
1
pf3

Partial preview of the text

Download Recurrence Relations: Solving Counting Problems with Recursive Functions and more Study notes Linear Algebra in PDF only on Docsity!

Jim Lambers Math 6A Spring Quarter 2003- Lecture 22 Notes

These notes correspond to Section 6.1 in the text.

Recurrence Relations

There are many counting problems for which the techniques we have previously studied are not useful. In the remaining lectures, we will discuss various advanced techniques for solving such problems. As counting problems are concerned with determining the cardinality of various sets, we begin with the use of recursion to describe sets, and, by extension, compute their cardinalities. The basic idea is to define a set S(n), whose contents depend on the integer n, in terms of sets of the form S(k) for some integer k < n. Then |S(n)| is an integer-valued function of n that is a recursively defined function, as discussed in the previous lecture. In this lecture, we will focus on the task of constructing functions recursively that describe the cardinality of such a set S(n). Then, we will consider the problem of obtaining an explicit definition of a recursively-defined function, since an explicit definition, while more difficult to obtain, is usually more efficient to evaluate, especially for large values of n. In a recursive definition of a function f : A → B, certain initial values of the function must be defined explicitly, for the basis step of the definition. The recursive step describes how f (x), for any x ∈ A that is not already considered in the basis step, is to be computed using values of f corresponding to other elements of A. Typically, f (x) is related to the other function values by an equation, which we now describe precisely.

Definition (Recurrence Relation) Let {an}∞ n=0 be a sequence. A recurrence relation is an equa- tion that relates an to an− 1 , an− 2 ,.. ., an−k, for some fixed integer k and each n ≥ n 0 , where n 0 is a nonnegative integer. A sequence whose terms satisfy a recurrence relation is called a solution of the recurrence relation.

Example The sequence of Fibonacci numbers {fn}∞ n=0, introduced in the previous lecture, is defined by the simple recurrence relation

fn = fn− 1 + fn− 2 , n ≥ 2 ,

with f 0 = 0 and f 1 = 1. 2

Modeling with Recurrence Relations

In the following examples, we illustrate how the problem of counting the number of elements in various sets can be solved more easily by describing these sets using recurrence relations, rather than using techniques such as the Product Rule and the Sum Rule to count the number of ways in which elements can be constructed.

Example Suppose that pairs of rabbits, where each pair consists of a male and female rabbit, reproduce in such a way that each pair that is at least two months old gives birth to a new pair every month. If, initially, there is one newborn pair, how many pairs are there after n months, for any nonnegative integer n? Let rn be the number of pairs after n months. This number must include the number of pairs that existed in the previous month, denoted by rn− 1. Furthermore, fn must include any pairs that were born in the nth month. The number of newborn pairs is equal to the number of pairs that are at least two months old, since each such pair gives birth to another pair. This number is rn− 2 , the number of pairs that existed two months ago. It follows that

rn = rn− 1 + rn− 2.

In other words, the sequence {rn} is the sequence of Fibonacci numbers, with r 0 = 1 and r 1 = 1, since there was initially one newborn pair that had to wait two months to reproduce. This sequence is essentially identical to the Fibonacci sequence {fn} defined above, in that for each n ≥ 1, fn = rn− 1. 2

Example A popular problem pertains to the Towers of Hanoi. The towers are three pegs, with disks of different sizes that can be stacked on the pegs. The problem is as follows: given n disks of n different sizes stacked on one peg, such that each disk is larger than the one above it, how many moves are needed to transfer all of the disks to one of the other pegs, in such a way that a larger disk is never placed on top of a smaller disk? Let Hn be the number of moves needed, and let the three pegs be numbered as peg 1, peg 2 and peg 3. We assume that the disks are initially stacked on peg 1, and they must be moved to peg 3. The problem of moving the n disks can be solved as follows: in order to move the largest disk that is at the bottom of the stack at peg 1, the stack at peg 3 must be empty, and no other disks can be stacked at peg 1. Therefore, the other n − 1 disks must be stacked, in order of size, on peg 2. Then the largest disk is moved to peg 3, and then we must solve the problem of moving the other n − 1 disks from peg 2 to peg 3. In short, we have reduced the problem of moving n disks to two problems in which n − 1 disks must be moved. Therefore, Hn satisfies the recurrence relation

Hn = 2Hn− 1 + 1,