cs320-2010-t1-midterm2-solution

cs320-2010-t1-midterm2-solution - CPSC 320 Midterm 2...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CPSC 320 Midterm 2 Monday, November 15th, 2010 [16] 1. Short Answers [4] a. Your boss asks you to design a divide-and-conquer algorithm to solve a problem whose input is an array of measurements that contain temperature data. What are the two main issues that you need to determine in order to design this algorithm? Solution : The two issues you need to determine are: How to break the problem into smaller subproblems, and How to combine the solutions to the smaller subproblems to get the solution to the initial problem. [4] b. In the Disjoint Sets data structure used by Kruskals minimum spanning tree algo- rithm, why does the union operation insert the root with the smaller rank as a child of the root with the larger rank, rather than the other way around? Solution : If we inserted the root with the larger rank as a child of the other root, the following sequence of n calls to unions : T new Node for i 1 to n do T union(T, new Node) endfor would result in a tree with height n 1 (and hence calls to find would take O(n) time). [4] c. Using the method of your choice, give a tight bound on the function T ( n ) described by the recurrence relation T ( n ) = braceleftbigg 6 T ( n/ 3) + 4 n 2 if n 13 17 if n 12 Solution : We use the Master theorem. Because n log b a = n log 3 6 , and log 3 6 < 2 , the only case that may apply is case 3. Let us check the regularity condition. af ( n/b ) = 6 f ( n/ 3) = 6 4( n/ 3) 2 = 6 4 n 2 / 9 = (2 / 3)4 n 2 and hence the regularity condition is satisfied as long as we choose 2 / 3 < < 1 ....
View Full Document

Page1 / 4

cs320-2010-t1-midterm2-solution - CPSC 320 Midterm 2...

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