Вы находитесь на странице: 1из 4

Fall 2010 - 91.

503 - Algorithms - 2nd Exam


Computer Science Department University of Massachusetts Lowell Lowell, MA 01854 Nov. 16, 2010.

Name: 1. Total: 2. /50 3. 4. 5. 6. 7.

Exam Time: 1h & 15m. Each problem is worth 10 points. 50 pts total. Choose any 5 problems. If needed, use the back of each page. 1. Parallel Processing. Dene the terms a. (2 pts) Work and Work Law b. (2 pts) Span and Span Law c. (2 pts) Parallelism Soln. see p. 779, and the end of the rst full paragraph of p. 780. d. (4 pts) You run a deterministic multithreaded algorithm on 4, 10 and 64 processors of an ideal parallel computer using a greedy scheduler, and the three runs yield T4 = 80 seconds, T10 = 32 seconds and T64 = 10 seconds. Is this reasonable given the laws you have quoted and the formula T1 T TP + T ? P Explain carefully. Soln. The work law (T1 P TP ), applied for all three data points implies that T1 320. The same three data points applied to the span law give that T 10. We now have the three inequalities from the formula above. You need to show that there exists at least one point in (T1 , T )-space that satises all inequalities. Since the three inequalities of the formula dene unbounded portions of the rst quadrant, try (T1 , T ) = (320, 10)... 2. Matrix Operations. Let M (n) be the time to multiply 2 n n matrices, and let S(n) denote the time required to square an n n matrix. Show that multiplication and squaring matrices have essentially the same diculty: M (n) O(S(n)) and S(n) O(M (n)). What assumptions do we need on S(n) - squaring may be dierent from simply multiplying a matrix 1

by itself - for the proof to go through? Hint: a trick similar to that used on inversion of matrices will work... Soln. Squaring is, clearly, no worse than multiplying, since the standard denition of squaring provides the algorithm that says multiply a matrix by itself. To show that multiplying is no worse than squaring, we need the assumption used for I(n) in Theorem 28.1, translated to S(n), along with the observation that the square of the 3n 3n matrix I A 0 0 I B 0 0 I is I 2A AB 0 I 2B 0 0 I

regardless of the algorithm we use to compute it. 3. PLU Decompositions. (4 pts) Describe the LU decomposition algorithm. (6 pts) Compute an LU decomposition 4 4 1 of the matrix 2 4 1 2 . 7 17

Make sure the intermediate steps are all visible. Soln. p. 822, Fig. 28.1 and the discussion starting at p. 819, providing the Schur Complement recursive algorithm. Since no P was asked for, no P should have been given. If you give a dierent algorithm, make sure you prove it works. 4. Linear Programming. (7 pts) Explaining the various steps of the Simplex Method, and your choices, solve the linear program: maximize 5x1 4x2 subject to x1 2x2 1 2 2x1 +x2

x1 , x2 0. (3 pts) What is the dual program? Explain. Soln. First Part. You rst need to move to slack form, and to show the existence of a basic feasible solution. Tell me which variables are basic and which non-basic. You end with maximize 5x1 4x2 subject to x3 = 1 x1 + 2x2 x4 = 2 2x1 x2 x1 , x2 , x3 , x4 2 0 .

The next step involves the decision of which variable to use as the entering variable, and which equation to use for the leaving variable. The leaving variable is easy - x1 has the only positive coecient in the function to maximize. The entering variable is a little harder: either equation gives the same range to x1 : 0 x1 1 and thus you can choose randomly, BUT: choosing the rst equation leads to a new basic feasible solution and an expression to maximize with all negative coecients for its variables, while choosing the second equation leads to an expression to maximize with a positive coecient for x2 . We need one more iteration of the algorithm (it does not mean that the solution is unbounded). For those of you who didnt, leaving fractions rather than moving to decimals was the better strategy. Soln. Second part. The denition of the dual is on p. 880. You should have given both the denition and the actual dual for the current problem. 5. Discrete Fourier Transform. (5 pts) Compute the DFT of the vector (1, 0, 2, 3). OR (10 pts) Compute the FFT of the vector (1, 0, 2, 3). In either case, you have to describe Soln. First part: the matrix is 1 1 1 1 and use the correct algorithm. 1 1 1 i 1 i , 1 1 1 i 1 i

and multiply matrix and (column) vector. Second part: use the algorithm on p. 911. Check you get the same answer... 6. RSA. Let p = 13, q = 17, n = 221, e = 5. a) (2.5 pts) What is (n)? b) (2.5 pts) What d should be used as the secret key and why? Explain how you obtained it. c) (2.5 pts) What is the encrypted value of the message M = 10? Show how you obtain it. d) (2.5 pts) Could we use e = 15? Explain. Soln. a) (p 1)(q 1) = 12 16 = 192. b) The usual solution is via the Extended Euclidean Algorithm, but some ddling with the numbers (with explanation: you can try successive multiples of 192, add 1, and check which such values are multiples of 5) would also return d = 77. c) 105 mod 221 = 108. d) No, since gcd(e, (n)) = gcd(15, 192) = 3 = 1, which is needed for a unique inverse.

7. Pattern Matching. a. (5 pt). Describe the Rabin-Karp algorithm. b. (5 pts) Apply it to the text T = 314159263535, searching for the pattern P = 15 working with modulo q = 9. How many spurious hits? How many valid ones? Show your work. Soln. The crucial step of the Rabin-Karp algorithm is formula (32.1) on p. 991. Without discussing it in enough detail so one can compute the current window value from the previous one, there is no description of the algorithm. Most everyone got the second part.

Вам также может понравиться