A sequence is a list of objects that are enumerated in some order. A
sequence may be defined recursively, that is, the n^{th} term
may be defined using one or more previous terms. Such a recursive
rule is called a recurrence relation. For example, the fibonacci sequence
may be defined as follows:

fib(1) = 1 fib(2) = 2 fib(n) = fib(n-1) + fib(n-2)Note that in addition to the recurrence relation (the third rule), there are two base cases (the first two rules). As for any recursive definition, at least one base case is always required. Although technically fib is defined by two base cases and one recurrence relation, we may loosely refer to the entire definition of fib as a recurrence relation.

S(1) = 2 S(n) = 2S(n-1)If we look at a few terms, we see that S(1)=2, S(2)=4, S(3)=8, S(4)=16, and so on -- in general S(n) = 2

But it is not always this easy to find a closed form solution. (Sometimes it isn't even possible.) For more difficult cases, it's useful to formalize the process above into three steps:

**Expand**the recurrence relation a few times and look for a pattern.**Guess**the closed form solution based on the pattern you see.**Verify**your guess using mathematical induction.

- | | -Adding a second square requires 3 more matchsticks:

- - | | | - -Adding another square would take 3 more matchsticks, and so on. If M(n) represents the number of matchsticks required to make n squares, we could define M as follows:

M(1) = 4 M(n) = 3 + M(n-1)To find a closed form solution for M, we first expand the recurrence relation a few times and look for a pattern:

M(n) = 3 + M(n-1) = 3 + (3 + M(n-2)) = 3 + 3 + M(n-2) = 3 + 3 + (3 + M(n-3)) = 3 + 3 + 3 + M(n-3)Stopping at this point, we see that at each step we are adding together some number of 3s and subtracting that same number from n in the index for M. (Note that we didn't actually do the addition to make 3+3=6 and 3+3+3=9; sometimes it's easier to see a pattern without the addition, sometimes with. Often you'll need to try both.) Calling that number k, we could generalize this as follows:

M(n) = 3k + M(n-k) k>=1To find a closed form solution we need to get rid of M(n-k) -- we want a definition for M(n) that does not rely on M. The only way to get rid of M(n-k) is to get it down to the base case so that we can substitute a non-recursive definition. The base case is defined for n=1, so if we let k=n-1, we will get what we want:

M(n) = 3(n-1) + M(n-(n-1)) = 3n-3 + M(1) = 3n-3 + 4 = 3n+1.This is our guess: M(n) = 3n+1.

Base case:(n=1) By def of M, M(1)=4. Using guess, M(1) = 3*1+1=4.Inductive step:If M(k) = 3k+1 then M(k+1) = 3(k+1)+1 = 3k+4.Proof:By the definition of M, M(k+1) = 3 + M(k). By the inductive hypothesis M(k) = 3k+1. Substituting this in above we get M(k+1) = 3 + 3k+1 = 3k + 4, which is what we wanted to show.

T(1) = 1 T(n) = 1 + T(n/2)To look for a closed form solution, we first expand the recurrence relation:

T(n) = 1 + T(n/2) = 1 + (1 + T(n/4)) = 2 + T(n/4) = 2 + (1 + T(n/8)) = 3 + T(n/8) = 3 + (1 + T(n/16)) = 4 + T(n/16)A pattern is emerging: at each step we have T(n) = k+T(n/2

T(n) = logThis is our guess._{2}n + T(n/2^{log2n}) = log_{2}n + T(n/n) = log_{2}n + T(1) = log_{2}n + 1.

To verify that given the definition of
T above, T(n)=log_{2}n+1, n>=1, we again use mathematical induction.
But since the n^{th} term of T depends not on the n-1 term but
on the n/2 term, we need to use the second principle in setting up the
inductive step.

Base case:(n=1) By def of T, T(1)=1. Using guess, T(1) = log^{2}1+1 = 0+1 = 1.Inductive step:If T(r) = log_{2}r+1, 1<=r<=k, then T(k+1) = log_{2}(k+1)+1.Proof:By the definition of T, T(k+1) = 1 + T((k+1)/2) By the inductive hypothesis T((k+1)/2) = log_{2}((k+1)/2)+1. (Note that (k+1)/2 will always be between 1 and k, so we can safely apply the inductive hypothesis.) Substituting this in above we get T(k+1) = 1 + log_{2}((k+1)/2)+1 = 2 + log_{2}((k+1)/2) = 2 + log_{2}(k+1) - log_{2}2 (remember log(a/b)=log a-log b) = 2 + log_{2}(k+1) - 1 = log_{2}(k+1) +1, which is what we wanted to show.