Solved Homework 6 for Discrete Structures | CS 173, Assignments of Discrete Structures and Graph Theory

Material Type: Assignment; Class: Discrete Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2005;

Typology: Assignments

Pre 2010

Uploaded on 03/16/2009

koofers-user-j6c
koofers-user-j6c 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS173: Discrete Mathematical Structures
Fall 2005
Homework #6
Due 10/16/05
Solution
Rubric 31 points
1. Give a recursive definition of the sequence
{a
n
},n=1,2,3,K
if
3 points each part. 1 point for base case, 2 points for recursive case.
a.
a
n
= 4n 2
.
Observing that
1
4( 1) 2 4 6
n
a n n
= =
, and the difference between
n
a
and
1n
a
is 4, the recursive definition is as follows:
1
2a=
,
1
4
n n
a a
= +
for n>1.
b.
a
n
=1+ (−1)
n
.
Notice that this sequence goes like 0, 2, 0, 2, … , the definition should
look like
. Formally, we use
( 1)
n
to control
±
:
1
0a=
,
1
2( 1)
n
n n
a a
= +
for n>1.
c.
a
n
=n(n+1)
.
Since
1
( 1)
n
a n n
=
and
1
( 1) ( 1) 2
n n
a a n n n n n
= + =
, we have:
1
2a=
,
1
2
n n
a a n
= +
for n>1.
2. Let S be the subset of the set of ordered pairs of integers defined recursively by:
Basis step:
(0,0) S.
Recursive step: if
(a,b)S
, then
(a+ 2,b+ 3) S
and
(a+ 3,b+ 2) S
a. List the elements of S produced by the first five applications of the
recursive definition (including the basis step).
b. Use induction to show that
5a+b
when
(a,b)S
. (That is, the
remainder is zero when
a+b
is divided by 5.)
a. From (0,0), we can construct (2,3) and (3, 2) (using the recursive step and
take (0,0) as
( , )a b
in the definition. From (2,3), we construct (4,6) and
(5,5), etc.
pf3
pf4

Partial preview of the text

Download Solved Homework 6 for Discrete Structures | CS 173 and more Assignments Discrete Structures and Graph Theory in PDF only on Docsity!

CS173: Discrete Mathematical Structures

Fall 2005

Homework

Due 10/1 6 /

Solution

Rubric 31 points

  1. Give a recursive definition of the sequence

{ an }, n = 1 , 2 , 3 ,K if

3 points each part. 1 point for base case, 2 points for recursive case. a.

an = 4 n − 2.

Observing that an^ − 1 =^4 (^ n^ −^1 )^ −^2 =^4 n −^6 , and the difference between an and an^ − 1 is 4, the recursive definition is as follows: a 1 (^) = (^2) , an = a (^) n (^) − 1 + (^4) for n>1. b.

an = 1 + (− 1 )

n . Notice that this sequence goes like 0, 2, 0, 2, … , the definition should look like an^ = a^ n^ − 1 ±^2. Formally, we use ( − 1 ) n to control ±: a 1 (^) = (^0) , 1 2 ( 1 ) n a n = a (^) n (^) −+ − (^) for n>1. c.

an = n ( n + 1 ).

Since a^ n − 1 =(^ n^ −^1 ) n and an^ − a^ n^ − 1 = n^ (^^ n^ +^1 )^ −(^ n^ −^1 )^ n^ =^2 n , we have: a 1 (^) = (^2) , an = a (^) n (^) − 1 + 2 n for n>1.

  1. Let S be the subset of the set of ordered pairs of integers defined recursively by: Basis step:

( 0 , 0 ) ∈ S.

Recursive step: if

( a , b ) ∈ S , then

( a + 2 , b + 3 ) ∈ S and

( a + 3 , b + 2 ) ∈ S

a. List the elements of S produced by the first five applications of the recursive definition (including the basis step). b. Use induction to show that € 5 a + b (^) when

( a , b ) ∈ S . (That is, the

remainder is zero when

a + b is divided by 5.)

a. From (0,0), we can construct (2,3) and (3, 2) (using the recursive step and take (0,0) as (^ a ,^^ b )^ in the definition. From (2,3), we construct (4,6) and (5,5), etc.

2 points. 0 points for no clue, 1 point for a good start, 2 points for totally correct. Subtract only a half point for minor errors. b. - Base case: (^0 ,^0 )^ ∈^ S , so a^ = b^ =^0 , a^ +^ b =^0. Therefore, € 5 a + b (^) ( 5 | (^0) ) is True.

  • Inductive hypothesis: Assume that

( a , b ) ∈ S and

€ 5 a + b.

  • Inductive step: if

( a , b ) ∈ S , then

( a + 2 , b + 3 ) ∈ S and

( a + 3 , b + 2 ) ∈ S.

Check (^ a^ +^2 )^ +^ (^ b^ +^3 )^ = a^^ +^ b +^5. According to the inductive hypothesis, € 5 a + b , we therefore have 5 | ( a + b ) + (^5). It applies to

( a + 3 , b + 2 ) ∈ S ,

too. 3 points. 1 point for base case, 1 point for inductive hypothesis, 1 point for argument. Note that the students might specify the use of the number of rule applications as the inductive counter, so that their implication may go from k to k+1 applications of the rules.

  1. Suppose you have a function that accepts a music genre as input, and gives some song from that genre as output, f: GenresSongs. Denote dance music (a music genre) by D , and rock (another music genre) by R. A playlist is just a list of songs. For example, f(D)f(D) is a playlist of two dance songs. Give an inductive definition of a good playlist, P , which is defined to be a playlist with more dance songs than rock songs. (You should assume that no song belongs to more than one genre.) The key fact here is that if a playlist has more dance songs than rock songs, then either it is the concatenation of two such lists, or else it is the concatenation of two such lists with one rock songs inserted either before the first, between them, or after the last list. This can be proved by looking at the running count of the excess of dance songs over rock songs as we read the list from left to right. Therefore, one recursive definition is as follows ( S is the set of good playlists): Base step: f^ (^ D )^ ∈ S Recursive step: if x^ ∈^ S and y^ ∈^ S , then xy^ ∈^ S , f^ (^ R )^ xy^ ∈^ S , xf^ (^ R^ ) y^ ∈^ S , and xyf ( R )∈ S. 5 points. Basically award 1 point for each rule. Be generous with almost correct solutions like the ones we came up with in section: 4 points for a definition that includes all the right strings plus a few extra, or that doesn’t quite include all the right strings, but gets close.
  2. a. Devise a recursive algorithm to find the n th term of the sequence defined by € a 0 = (^1) , € a 1 = (^2) , € a 2 = (^3) , and € an = an − 1 + an − 2 + an − 3 , for

n = 3 , 4 , 5 K .

c. Algorithm from part b is more efficient. Assume each addition operation takes constant time, then part a has a complexity of (^3 ) O n while part b is O (^^ n )^. Details: Notice that in part a, the recursive algorithm calls itself three times in the procedure body. Each of the three procedures will call itself three times respectively and so on. This “recursion” goes on until one of the base cases is hit and returns. We can imagine the process of recursively calling itself to be the process of constructing a tree. The root, recFindA (n), has three children, namely, recFindA (n-1), recFindA (n-2), and recFindA (n-3). Each of these children grows its own subtree. (Take recFindA (n-1) for example, it has recFindA (n-2), recFindA (n-3), and recFindA (n-4) as its children). Leaf nodes are just base cases, recFindA (0), recFindA (1), and recFindA (2). As stated above, this inefficient recursive algorithm has a time complexity O ( 3 n ) because of its tree structure (each internal nodes has 3 children). Why this exponential growth happens? It is because we have redundant computations. For example, we want the result of recFindA (6). We need recFindA (5), recFindA (4), and recFindA (3). Then we first compute recFindA (5). In this procedure, we need recFindA (3). Similarly, recFindA (4) needs the result of recFindA (3). So we at least compute recFindA (3) three times. Each time, we compute recFindA (3) from scratch. They are repetitive and therefore redundant. Is there a way to improve this? The answer is yes. We just reuse the result previously computed. That is, we only compute recFindA (3) once. When we encounter it the second time, we just use the result computed in the first round. Implementation is not covered by CS173. On the other hand, the iterative algorithm only takes linear time. Basically, it is a loop (for, while, etc.). In each iteration, we do two things: update three variables and compute a temporary result by adding three variables. Obviously, it is linear to the input index n: we have O(n) iterations, each has a fixed set of operations. 4 points. 2 for explaining the inefficiency of the tree structure, and 2 for explaining the contrasting efficiency of the iterative algorithm.