


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Discrete Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Fall 2005;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



3 points each part. 1 point for base case, 2 points for recursive case. a.
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.
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.
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.
Recursive step: if
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
remainder is zero when
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.
€ 5 a + b.
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
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.
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.