
CS173: Discrete Mathematical Structures
Spring 2006
Homework #7
Due 12/03/06
1. (6 points, 2 points each part)
Give a recursive definition of the sequence
if
a. an=2n+n
b. an=2n+(-2)n
c. an=n2+2n+1
2. (16 points, 4 points each part, 2 bonus points for efficient solution for (a))
a. Give a recursive algorithm for computing xy, where x and y are positive
integers. Efficient implementation will grant bonus points.
b. Describe a recursive algorithm to compute the sum of the digits of a
positive integer. You may only use arithmetic operators (such as floor and
remainder also known as div and mod) and not string operators (such as
“get the 5-th digit”) in your solution.
c. A partition of a positive integer n is a way to write n as a sum of positive
integers. For example, 7=3+2+1+1 is a partition of 7. Give a recursive
algorithm to find the number of partitions of a positive integer.
d. What is the number of recursive calls these functions make (both the one
you gave in (a) (b) and in (c)). Note that here we're asking you what's
3. (12 points, 4 points each part)
Consider the following recursive definition:
f(m,n)=
0 if m>=1 and n=0
2 if m>=1 and n=1
2n if m=0;
f(m-1,f(m,n-1)) if m>=1 and n>=2.
a. Show that f(1,n)= 2n for all n>=1.
b. Show that f(m,2)=4 for all m>=1.