{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ps9sol - Introduction to Algorithms Massachusetts Institute...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms December 8, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 34 Problem Set 9 Solutions Reading: Chapters 32.1–32.2, 30.1–30.2, 34.1–34.2, 35.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 in 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. Three-hole punch your paper on submissions. 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 the 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. Full credit will be given only to correct algorithms that are which are described clearly . Convoluted and obtuse descriptions will receive low marks. Exercise 9-1. On-line String Matching Recall that in an on-line algorithm, the input is generated as the algorithm is running. The idea is to solve the problem efficiently before seeing all the input. You can’t scan forward to look at ’future’ input, but you can store all input seen so far, or some computation on it. (a) In this setting, the text T [1 . . . n ] is being broadcast on the network, one letter at a time, in the order T [1] , T [2] , . . . . You are interested in checking if the text seen so far contains a pattern P , where P has length m . Every time you see the next letter of the text T , you want to check if the text seen so far contains P .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}