CS131 Part III, Sequences and Series CS131 Mathematics for Computer Scientists II Note 16 RECURRENCES A recurrence is a rule which defines each term of a sequence using the preceding terms. The Fibonacci Sequence. The Fibonacci sequence F n ) is defined by the following recurrence: together with the initial conditions: F n = F n 1 + F n n ) F 0 = 0, F 1 = 1. Since the first two terms are known, we can use the recurrence to compute later terms of the sequence, giving 0, 1, 1,, 3,, 8, 13, 1, 34,,.... The Towers of Hanoi. This puzzle was invented by the French mathematician Edouard Lucas in 1883. It consists of eight disks, initially stacked in decreasing size on one of three pegs. The objective is to move the tower to one of the other pegs by moving one disk at a time and never moving a larger one onto a smaller. This leads to the recurrence T n = T n 1 + 1. With T 0 = 0 this gives the sequence 0, 1, 3, 7, 1, 31, 63,.... It is easy to guess that T n = n 1 for each n 0 and this formula can then be proved by induction. This is known as a closed form for T n and allows us to compute terms of the sequence immediately in terms of n. Linear recurrences. In this note we look at methods for solving linear recurrences with constant coefficients. These have the form x n + a 1 x n 1 + + a k x n k = fn) where a 1,..., a k are constants and f is some given function. If the values of the first k terms are given, then this recurrence defines a unique sequence x n ). We begin by looking at homogeneous recurrences, which are those with fn) = 0 for all n, and we will also assume k = the generalisation to higher order recurrences is fairly straightforward). 16 1
We wish to find the general solution of the recurrence x n + ax n 1 + bx n = 0. When b = 0 it is easy to see that the solution is given by x n = a) n x 0. This suggests that in the general case we should look for solutions of the form x n = λ n A, where λ and A are constants. Now x n = λ n is a solution of x n + ax n 1 + bx n = 0 λ n + aλ n 1 + bλ n = 0 λ n λ + aλ + b) = 0 λ = 0 or λ + aλ + b = 0. Auxiliary equation. The equation λ + aλ + b = 0 is called the auxiliary equation of the recurrence x n + ax n 1 + bx n = 0. If the auxiliary equation has two distinct solutions λ 1 and λ, then it is easy to verify that x n = Aλ n 1 + Bλ n is a solution of the recurrence for any constants A and B. If the first two terms of the sequence x n ) are given, then they can be used to find the values of A and B. If the auxiliary equation has only a single solution for λ then a 4b = 0, so b = a /4 and λ = a/. In this case x n = Aλ n is a solution of the recurrence for any A, but is not the general solution. However x n = nλ n is also a solution since this gives, on substitution, x n + ax n 1 + bx n = nλ n + an 1)λ n 1 + bn )λ n = nλ n λ + aλ + b) λ n aλ + b) = nλ n 0 λ n 0 = 0. The second term is 0 since aλ = a / and b = a /.) Hence the general solution is x n = Aλ n + Bnλ n where A and B are constants. Solution of the recurrence x n + ax n 1 + bx n = 0. Let λ 1, λ be the roots of the auxiliary polynomial λ + aλ + b, then if λ 1 λ, x n = Aλ n 1 + Bλ n, if λ 1 = λ, x n = Aλ n 1 + Bnλ n. If the first two terms of the sequence x n ) are known, then they can be used to find the constants A and B. Problem. Find a closed form for the terms of the Fibonacci sequence. 16
Solution. Here we have F n F n 1 F n = 0, so the auxiliary equation is λ λ 1 = 0, which has roots Hence we have λ 1 = 1 + F n = A and λ = 1. 1 + ) n 1 ) n + B. Finding A and B is easy since we have F 0 = 0 and F 1 = 1. Thence F n = 1 1 + ) n 1 1 ) n. The number 1 + )/ or 1.61803... is called the golden ratio and is often denoted by φ. Note that F n is an integer expression, despite appearances. Since 1 )/ < 1, the second term in the above closed form for F n becomes smaller as n increases. In fact we have 1 1 ) n < 1 for all n, which gives the formula: ) φ n F n = rounded to the nearest integer. We now look at the case of a non- Non-homogeneous recurrences. homogeneous recurrence of the form x n + ax n 1 + bx n = fn) where a and b are constants. Suppose that x n = h n is the general solution of the corresponding homogeneous recurrence so that h n + ah n 1 + bh n = 0, and that x n = p n is any particular solution of the original recurrence so that p n + ap n 1 + bp n = fn). 16 3
Then x n = h n +p n is a solution of the recurrence since, on adding the above, h n + p n ) + ah n 1 + p n 1 ) + bh n + p n ) = h n + ah n 1 + bh n ) + p n + ap n 1 + bp n ) = 0 + fn) = fn). It follows that x n = h n +p n is the general solution of the original recurrence. Solution of the recurrence x n + ax n 1 + bx n = fn). 1) Find the general solution x n = h n of the homogeneous recurrence: x n + ax n 1 + bx n = 0 solution will contain two arbitrary constants). ) Find any particular solution x n = p n of the original recurrence: x n + ax n 1 + bx n = fn). 3) The general solution of the original recurrence is then given by x n = h n + p n. In general finding a particular solution of the recurrence will not be easy! x n + ax n 1 + bx n = fn) Some useful techniques are: If f is constant, say fn) = k for all n, then it is easy to find a constant particular solution provided 1 + a + b 0). For if x n = c for all n, then substituting into the recurrence x n +ax n 1 +bx n = k gives c + ac + bc = k or c = k/1 + a + b). For a more complicated polynomial) fn), try to find a particular solution which is also a polynomial in n, e.g., try x n = k or x n = k 1 n + k or x n = k 1 n + k n + k 3,.... Example. Find the general solution of the recurrence x n 10.1x n 1 + x n =.7n. Solution. The homogeneous recurrence x n 10.1x n 1 + x n = 0 has auxiliary equation λ 10.1λ + 1 = 0 or λ 10)λ 1/10) = 0, 16 4
and so has general solution x n = A10 n ) + B/10 n. To find a particular solution of we try x n = Cn + D. This gives x n 10.1x n 1 + x n =.7n, Cn+D 10.1Cn 1)+D)+Cn )+D = 8.1Cn+8.1D 8.1C =.7n. Since this holds for all n, we have 8.1C =.7, 8.1D 8.1C = 0 so C = D = 1/3. Hence the general solution of the recurrence is x n = 10 n A + B 10 n + n + 1 3. ABSTRACT Content definition, well-known examples, solution of linear recurrences homogeneous and non-homogeneous) In this Note we study the solution of linear recurrences. Those students familiar with the solution of linear ordinary differential equations will recognise much that is in this Note. Because recurrence relationships are closely related to recursive algorithms, recurrences arise naturally in the analysis of the latter. History The most useful recurrences are non-linear and are generally beyond the scope of this module. These are to be found mostly in the area of mathematical physics. 16