Skip to main content
Logo image

Applied Discrete Structures

Section 8.4 Some Common Recurrence Relations

In this section we intend to examine a variety of recurrence relations that are not finite-order linear with constant coefficients. For each part of this section, we will consider a concrete example, present a solution, and, if possible, examine a more general form of the original relation.

Subsection 8.4.1 A First Basic Example

Consider the homogeneous first-order linear relation without constant coefficients, S(n)nS(n1)=0, n1, with initial condition S(0)=1. Upon close examination of this relation, we see that the nth term is n times the (n1)st term, which is a property of n factorial. S(n)=n! is a solution of this relation, for if n1,
S(n)=n!=n(n1)!=nS(n1)
In addition, since 0!=1, the initial condition is satisfied. It should be pointed out that from a computational point of view, our “solution” really isn’t much of an improvement since the exact calculation of n! takes n1 multiplications.
If we examine a similar relation, G(k)2kG(k1)=0, k1 with G(0)=1, a table of values for G suggests a possible solution:
k012345G(k)122326210215
The exponent of 2 in G(k) is growing according to the relation E(k)=E(k1)+k, with E(0)=0. Thus E(k)=k(k+1)2 and G(k)=2k(k+1)/2. Note that G(k) could also be written as 2021222k, for k0, but this is not a closed form expression.
In general, the relation P(n)=f(n)P(n1) for n1 with P(0)=f(0), where f is a function that is defined for all n0, has the “solution”
P(n)=k=0nf(k)
This product form of P(n) is not a closed form expression because as n grows, the number of multiplications grow. Thus, it is really not a true solution. Often, as for G(k) above, a closed form expression can be derived from the product form.

Subsection 8.4.3 Analysis of Bubble Sort and Merge Sort

The efficiency of any search algorithm such as the binary search relies on fact that the search list is sorted according to a key value and that the search is based on the key value. There are several methods for sorting a list. One example is the bubble sort. You might be familiar with this one since it is a popular “first sorting algorithm.” A time analysis of the algorithm shows that if B(n) is the worst-case time needed to complete the bubble sort on n items, then B(n)=(n1)+B(n1) and B(1)=0. The solution of this relation is a quadratic function B(n)=12(n2n). The growth rate of a quadratic function such as this one is controlled by its squared term. Any other terms are dwarfed by it as n gets large. For the bubble sort, this means that if we double the size of the list that we are to sort, n changes to 2n and so n2 becomes 4n2 . Therefore, the time needed to do a bubble sort is quadrupled. One alternative to bubble sort is the merge sort. Here is a simple version of this algorithm for sorting F={r(1),r(2),,r(n)}, n1. If n=1, the list is sorted trivially. If n2 then:
  1. Divide F into F1={r(1),,r(n/2)} and F2={r(n/2+1),,r(n)}.
  2. Sort F1 and F2 using a merge sort.
  3. Merge the sorted lists F1 and F2 into one sorted list. If the sort is to be done in descending order of key values, you continue to choose the higher key value from the fronts of F1 and F2 and place them in the back of F.
Note that F1 will always have n/2 items and F2 will have n/2 items; thus, if n is odd, F2 gets one more item than F1. We will assume that the time required to perform Step 1 of the algorithm is insignificant compared to the other steps; therefore, we will assign a time value of zero to this step. Step 3 requires roughly n comparisons and n movements of items from F1 and F2 to F; thus, its time is proportional to n. For this reason, we will assume that Step 3 takes n time units. Since Step 2 requires T(n/2)+T(n/2) time units,
(8.4.9)T(n)=n+T(n/2)+T(n/2)
with the initial condition
(8.4.10)T(1)=0
Instead of an exact solution of these equations, we will be content with an estimate for T(n). First, consider the case of n=2r, r1:
T(21)=T(2)=2+T(1)+T(1)=2=12T(22)=T(4)=4+ T(2)+T(2)=8=24T(23)=T(8)=8+T(4)+T(4)=24=38T(2r)=r2r=2rlog22r
Thus, if n is a power of 2, T(n)=nlog2n. Now if, for some r2, 2r1n2r, then (r1)2r1T(n)<r2r. This can be proved by induction on r. As n increases from 2r1 to 2r, T(n) increases from (r1)2r1to r2r and is slightly larger than nlog2n. The discrepancy is small enough so that Te(n)=nlog2n can be considered a solution of (8.4.9) and (8.4.10) for the purposes of comparing the merge sort with other algorithms. Table 8.4.7 compares B(n) with Te(n) for selected values of n.
Table 8.4.7. Comparison of Times for Bubble Sort and Merge Sort
n B(n) Te(n)
10 45 34
50 1225 283
100 4950 665
500 124750 4483
1000 499500 9966

Subsection 8.4.4 Derangements

A derangement is a permutation on a set that has no “fixed points”. Here is a formal definition:

Definition 8.4.8. Derangement.

A derangement of a nonempty set A is a permutation of A (i.e., a bijection from A into A) such that f(a)a for all aA.
If A={1,2,...,n}, an interesting question might be “How many derangements are there of A?” We know that our answer is bounded above by n!. We can also expect our answer to be quite a bit smaller than n! since n is the image of itself for (n1)! of the permutations of A.
Let D(n) be the number of derangements of {1,2,...,n}. Our answer will come from discovering a recurrence relation on D. Suppose that n3. If we are to construct a derangement of {1,2,,n}, f, then f(n)=kn. Thus, the image of n can be selected in n1 different ways. No matter which of the n1 choices we make, we can complete the definition of f in one of two ways. First, we can decide to make f(k)=n, leaving D(n2) ways of completing the definition of f, since f will be a derangement of {1,2,,n}{n,k}. Second, if we decide to select f(k)n, each of the D(n1) derangements of {1,2,,n1} can be used to define f. If g is a derangement of {1,2,,n1} such that g(p)=k, then define f by
f(j)={n if j=pk if j=ng(j) otherwise 
Note that with our second construction of f, f(f(n))=f(k)n, while in the first construction, f(f(n))=f(k)=n. Therefore, no derangement of {1,2,...,n} with f(n)=k can be constructed by both methods.
To recap our result, we see that f is determined by first choosing one of n1 images of n and then constructing the remainder of f in one of D(n2)+D(n1) ways. Therefore,
(8.4.11)D(n)=(n1)(D(n2)+D(n1))
This homogeneous second-order linear relation with variable coefficients, together with the initial conditions D(1)=0 and D(2)=1, completely defines D. Instead of deriving a solution of this relation by analytical methods, we will give an empirical derivation of an approximation of D(n). Since the derangements of {1,2...,n} are drawn from a pool of n! permutations, we will see what percentage of these permutations are derangements by listing the values of n!, D(n), and D(n)n!. The results we observe will indicate that as n grows, D(n)n! hardly changes at all. If this quotient is computed to eight decimal places, for n12, D(n)/n!=0.36787944. The reciprocal of this number, which D(n)/n! seems to be tending toward, is, to eight places, 2.7182818. This number appears in so many places in mathematics that it has its own name, e. An approximate solution of our recurrence relation on D is then D(n)n!e.

Exercises 8.4.5 Exercises

1.

Solve the following recurrence relations. Indicate whether your solution is an improvement over iteration.
  1. nS(n)S(n1)=0, S(0)=1.
  2. T(k)+3kT(k1)=0, T(0)=1.
  3. U(k)k1kU(k1)=0, k2, U(1)=1.
Answer.
  1. S(n)=1/n!
  2. U(k)=1/k, an improvement.
  3. T(k)=(3)kk!, no improvement.

2.

Prove that if n0, n/2+n/2=n. (Hint: Consider the cases of n odd and n even separately.)

3.

Solve as completely as possible:
  1. T(n)=3+T(n/2), T(0)=0.
  2. T(n)=1+12T(n/2), T(0)=2.
  3. V(n)=1+Vn/8), V(0)=0. (Hint: Write n in octal form.)
Answer.
  1. T(n)=3(log2n+1)
  2. T(n)=2
  3. V(n)=log8n+1

4.

Prove by induction that if T(n)=1+T(n/2), T(0)=0, and 2r1n<2r , r1, then T(n)=r.
Hint.
Prove by induction on r.

5.

Use the substitution S(n)=T(n+1)/T(n) to solve T(n)T(n2)=T(n1)2 for n2, with T(0)=1, T(1)=6, and T(n)0.
Answer.
The indicated substitution yields S(n)=S(n+1). Since S(0)=T(1)/T(0)=6, S(n)=6 for all n. Therefore T(n+1)=6T(n)T(n)=6n.

6.

Consider the sequence S defined by T(n)2T(n1)2=1 for n1, with the conditions T(0)=10 and T(n)0 for all n. Use the substitution G(n)=T(n)2 to solve for S.

7.

Solve as completely as possible:
  1. Q(n)=1+Q(n), n2, Q(1)=0.
  2. R(n)=n+R(n/2), n1, R(0)=0.
Answer.
  1. A good approximation to the solution of this recurrence relation is based on the following observation: n is a power of a power of two; that is, n is 2m, where m=2k , then Q(n)=1+Q(2m/2). By applying this recurrence relation k times we obtain Q(n)=k. Going back to the original form of n, log2n=2k or log2(log2n)=k. We would expect that in general, Q(n) is log2(log2n). We do not see any elementary method for arriving at an exact solution.
  2. Suppose that n is a positive integer with 2k1n<2k. Then n can be written in binary form, (ak1ak2a2a1a0)two with ak1=1 and R(n) is equal to the sum Σk1i=0 (ak1ak2ai)two. If 2k1n<2k, then we can estimate this sum to be between 2n1 and 2n+1. Therefore, R(n)2n.

8.

Suppose Step 1 of the merge sort algorithm did take a significant amount of time. Assume it takes 0.1 time unit, independent of the value of n.
  1. Write out a new recurrence relation for T(n) that takes this factor into account.
  2. Solve for T(2r), r0.
  3. Assuming the solution for powers of 2 is a good estimate for all n, compare your result to the solution in the text. As gets large, is there really much difference?
You have attempted of activities on this page.