MT-Sol - Midterm solutions: Ques 1. - There are two methods...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Midterm solutions: Ques 1. ------ There are two methods of solving this problem. well as depth of a tree. Find-Dia (root r) Let the children of r be c_1, c_2, etc. Run Find-Dia on c_1, c_2, etc, keeping track of the maximum diameter found so far and the two largest depths found so far. Call these Dia, Depth1 and Depth2. Return depth 1+max(Depth1,Depth2) Return diameter max(Dia,Depth1+Depth2+2) Running time: At each node, we do a constant amount of work, therefore total time is O(n). Method 2: 1. Start with an arbitrary root and find the deepest node v using DFS/BSF 2. Start with v as the root and find the depth of the deepest node u. 3. Return this depth = d(u,v) as the diameter. Running time: O(n) because each step takes O(n). Ques 2. ------ MRS(1,n)
Background image of page 1

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

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

This note was uploaded on 02/17/2011 for the course CS 367 taught by Professor Marvinsolomon during the Spring '08 term at Wisconsin.

Page1 / 2

MT-Sol - Midterm solutions: Ques 1. - There are two methods...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online