ps - Introduction to Algorithms Massachusetts Institute of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Professors Erik Demaine and Shafi 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 three-hole punched paper. You will often be called upon to “give an algorithm” to solve a certain problem. Your write-up 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 1-1. Do Exercise 2.3-5 on page 37 in CLRS. Exercise 1-2. Do Exercise 2.3-7 on page 37 in CLRS. Exercise 1-3. Do Exercise 3.1-1 on page 50 in CLRS. Exercise 1-4. Do Exercise 3.1-3 on page 50 in CLRS. Exercise 1-5. Do Exercise 4.1-6 on page 67 in CLRS. 2 Handout 6: Problem Set 1 Problem 1-1. Rank the following functions by order of growth; that is, find 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 55-56 of CLRS.) Problem 1-2. 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 post-conditions 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 1-4. 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 upper-left and lower-right elements is at most the sum of the upper-right and lower-left 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 1-3. 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) “ 1”0 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, first 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 even-numbered 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 divide-and-conquer 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 “ Vvt #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 £ £ Vvt #A¡£ Vvt 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 divide-and-conquer 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.

Ask a homework question - tutors are online