# ps9sol - Introduction to Algorithms Massachusetts Institute...

This preview shows pages 1–3. Sign up to view the full content.

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

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

Unformatted text preview: Introduction to Algorithms November 21, 2001 Massachusetts Institute of Technology 6.046J/18.410J Singapore-MIT Alliance SMA5503 Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson Handout 32 Problem Set 9 Solutions MIT students: This problem set is due in lecture on Wednesday, November 21 . SMA students: This problem set is due after recitation on Friday, November 23 . Reading: Chapters 22 and 24. 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 instructor and time, the date, and the names of any students with whom you collaborated. MIT students: Each problem should be done on a separate sheet (or sheets) of three-hole punched paper. SMA students: Each problem should be done on a separate sheet (or sheets) of two-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 convo- luted and obtuse descriptions. 2 Handout 32: Problem Set 9 Solutions Exercise 9-1. Do exercise 22.2-7 on page 539 of CLRS. Solution: Run BFS on any node × in the graph, remembering the node Ù discovered last. Run BFS from Ù remembering the node Ú discovered last. d Ù ;Ú is the diameter of the tree. Correctness: Let a and b be any two nodes such that d a ;b is the diameter of the tree. There is a unique path from a to b . Let Ø be the first node on that path discovered by BFS. If the paths Ô from × to Ù and Ô from a to b do not share edges, then the path from Ø to Ù includes × so d Ø ;Ù d × ;Ù d Ø ;Ù d × ;a d Ø ;Ù d Ø ;a d b ;Ù d b ;a : Since d a ;b d Ù ;b , d a ;b = d Ù ;b . If the paths Ô and Ô do share edges, then Ø is on Ô . Since Ù was the last node found by B F , d Ø ;Ù d Ø ;a . Since Ô is the longest path, d Ø ;a d Ø ;Ù . Thus d Ø ;a = d Ø ;Ù and d Ù ;b = d a ;b . d a ;b d Ù ;Ú and d Ù ;Ú d Ù ;b so all three are equal. Thus d Ù ;Ú is the diameter of the tree....
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

ps9sol - Introduction to Algorithms Massachusetts Institute...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online