This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Professors Erik Demaine and Shaﬁ Goldwasser September 6, 2002 6.046J/18.410J Handout 6 Problem Set 1
This problem set is due in lecture on Monday, September 16. Reading: Chapters 1–4 (excluding 4.4); 28.2; 30.1 Both exercises and problems should be solved, but only the problems should be turned in. Exercises are intended to help you master the course material. Even though you should not turn in the exercise solutions, you are responsible for material covered by the exercises. Mark the top of each sheet with your name, the course number, the problem number, your recitation section, the date, and the names of any students with whom you collaborated. Each problem should be done on a separate sheet (or sheets) of threehole punched paper. You will often be called upon to “give an algorithm” to solve a certain problem. Your writeup should take the form of a short essay. A topic paragraph should summarize the problem you are solving and what your results are. The body of your essay should provide the following: 1. A description of the algorithm in English and, if helpful, pseudocode. 2. At least one worked example or diagram to show more precisely how your algorithm works. 3. A proof (or indication) of the correctness of the algorithm. 4. An analysis of the running time of the algorithm. Remember, your goal is to communicate. Graders will be instructed to take off points for convoluted and obtuse descriptions. Exercise 11. Do Exercise 2.35 on page 37 in CLRS. Exercise 12. Do Exercise 2.37 on page 37 in CLRS. Exercise 13. Do Exercise 3.11 on page 50 in CLRS. Exercise 14. Do Exercise 3.13 on page 50 in CLRS. Exercise 15. Do Exercise 4.16 on page 67 in CLRS. 2 Handout 6: Problem Set 1 Problem 11. Rank the following functions by order of growth; that is, ﬁnd an arrangement of the functions satisfying , , ..., . Partition your list into equivalence classes such that and are in the same class if and only if . (The function is discussed on pages 5556 of CLRS.) Problem 12. Consider the searching problem: given an array and a value , output an index such that or the special value if does not appear in . If the array is sorted, we can perform a binary search: compare with the midpoint of the array and repeat the search on one half of array, eliminating the other half from further consideration. (a) Write pseudocode for binary search as a recursive procedure. (b) Rewrite your binary search procedure in an iterative style. (c) Formally state pre and postconditions for your iterative procedure. Write a loop invariant, and prove it correct. Then prove your entire procedure correct (what else do you need to prove?). Problem 14. Consider an array of real numbers. If we pick two rows and two columns, they intersect at exactly four elements. We say that those rows and columns satisfy the Monge property if the sum of the upperleft and lowerright elements is at most the sum of the upperright and lowerleft elements. Furthermore, we say that is a Monge array if all choices of two rows t t l ) mk (f) (e) (Assume i 3 a (d) (c) (b) (Assume (Warning: the Master Theorem does not apply here.) .) i D 3 i (a) .) i Problem 13. Solve the following recurrences. Supply both upper ( or ) and lower ( bounds, and make them as tight as possible. Justify your answers. (You may assume that in all cases, except where noted.) 3 i '#& ¡ t $¡ %# hg 97 Y) @ f d ¡ sc i Wb WS qVU§VUS ) t x )©© u yw¨¨© i vt Y `)
¤§ " 21 ) ¦ !§ ¦ ) @ ) r7 ) B@ ) C97 p ) 97 0 ( ) ¤§ ¦ ¡ @ @ 0) 97 B 97 WS XVUT D G R d f¢¡ ec Wb WD [email protected] ) CA97 j) 10 i D 0 ) ) @8 ) ) " Ar7 2 "g ) ih¡ a 2 ) p97 ) f0Cq0 D 0 eR d ) ) ) R 1 a 2 2 ) ) ) ) ) 0 ) ¦ 2 D ) ) ) " 1 D 2 2 Q IIH F F E ¥&P¥G¡ ¢D @ WS qVUG2) 97 Wa i u x t ¥216532 ( ) 4 ) ¡ £ © © © £ ¦ £¡ ¢¥¨¨¨¨§¥¤¢ or ) Handout 6: Problem Set 1 3 is Monge if for all For example, the following array is Monge. (We have outlined two rows and columns; notice that .) 10 17 24 11 45 36 75 17 22 28 13 44 33 66 13 16 22 6 32 19 51 28 29 34 17 37 21 53 23 23 24 7 23 6 34 (a) Prove that an array is Monge if and only if adjacent rows and columns have the Monge property. More formally, prove that is Monge if and only if for all and : (Hint: For the “if” part, ﬁrst use induction on just the rows.) (b) Let be the index of the column containing the leftmost minimum element of row in matrix . For example, we have outlined the leftmost minimum elements in the Monge array from above: 10 17 24 11 45 36 75
( ( 17 22 28 13 44 33 66 13 16 22 6 32 19 51 28 29 34 17 37 21 53 23 23 24 7 23 6 34 1. Construct a submatrix of consisting of the evennumbered rows of . 2. Recursively determine for each row of . for the rows of , using the values returned in step 2. 3. Compute t ( (c) Here is a divideandconquer algorithm that computes Monge array : for every row t ! t k ( Prove that for any Monge array . of an ¢ k£©© i '¨¨© £ D £ i u ©x hA¡£ i Vvt #x i f u © A¡£ t #x ¢ £ t x u )l ¡£ t and two columns satisfy the Monge property. Formally: that and , we have:
£ f £ A¡£ £ and such u t £ fu x ¢ £ t #A¡£ t x u xi k t t ¡£ t £ £ Vvt #A¡£ Vvt u x u i ) # $( £ ! "t ¢ §¥ D )£©©© i e'¨¨¨£ D £ i t £ ¤i £ ( i A k t £ f D £ ¨ ©a )l ( ¥ ¦ £ ¤i k AD D 4 Explain how to perform step in Handout 6: Problem Set 1 (d) Write a recurrence describing the running time of the divideandconquer algorithm described in part (d). Prove that its solution is . (Assume that our representation of matrices allows step 1 to construct from in time.) k
t k q97 ) @8 ! t k
2 ) k
a time. ...
View
Full
Document
This note was uploaded on 01/01/2011 for the course CS 5503 taught by Professor Charlese.leiserson during the Fall '01 term at MIT.
 Fall '01
 CharlesE.Leiserson
 Algorithms

Click to edit the document details