Before defining terminology we will experiment with the following problems. Except where directed you should write code to perform the calculations so we concentrate on the results rather than the calculations.
Sometimes directly calculating the value of a function can be difficult. In the examples above each value of the function is based on the previous. The first example was \(f(n)=\sqrt{2+f(n-1)}.\) The second example was \(g(n)=\frac{1}{1+g(n-1)}.\) This is known as recursive definition.
The first month there was one pair of rabbits. The second month there was still one pair of rabbits. Starting the third month and continuing every month thereafter, the number of pairs of rabbits is the sum of the previous two months. Thus the third month there are \(1+1=2\) pairs of rabbits. The fourth month there are \(1+2=3\) pairs of rabbits. This produces the following sequence.
It is possible to count using recursive functions as well. Consider the number of words from the alphabet \(\{\)a,b,c,d,e\(\}\) with no two, consecutive aβs. For words of length one there are no restrictions, so there are 5. For words of length two all combinations except βaaβ are acceptable. Thus there are \(25-1=24\) words of length two. For words of length three all combinations except βaaaβ, βaaX,β and βXaaβ are allowable. This removes \(1+4+4=9\) words leaving \(5^3-9=116\) acceptable words.
For longer words of length \(n\text{,}\) note that removing the last letter produces an acceptable word of length \(n-1.\) Appending b,c,d,e to the end of these length \(n-1\) words produces another acceptable word. This constructs \(4a_{n-1}\) acceptable words of length \(n.\)
The only words to which an βaβ can be appended are those that ended in b,c,d, or e. These could have been appended to any word of length \(n-2.\) Thus appending βaβ constructs an additional \(4a_{n-2}.\)
While it is possible to produce a function that provides the \(n\)th term, this is generally not easy. For linear recurrence relations the technique demonstrated here will always work.
Guido is superstitious and will not take food from two, adjacent bins at a buffet. If the buffet is a line having \(n\) bins each containing distinct food, how many different combinations of food can he choose? Note he can eat as many items as he wants.
Guido walks up stairs taking one or two steps at a time. Find a recursive formula for the number of ways he could end up at step \(n.\) Note he starts at step 0 (not on the stairs).