AlgGradFall06Fnl

AlgGradFall06Fnl - Algorithms CSE 5211 Fall 2006 Final Exam...

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

View Full Document Right Arrow Icon
Algorithms CSE 5211 Fall 2006 Final Exam Points 50 Time 115 min Answer sketches (not detailed answers) below. 1a. Write an O(log n ) divide and conquer algorithm for calculating a n , for a > 0 and n 1. Analyze its complexity. [Hint: If you have written an O( n ) divide an conquer algorithm before write it again and check how to improve it.] [5] Instead of making two exactly same calls for a n/2 (or a (n-1)/2 ) call it once and use the stored value. T(n) = 2T(n/2) + O(1) leads to O(log n). 1b. Following is the fragment of an algorithm where M is a 2-dimensional array and f j is an one-dimensional array. What is the time-complexity for this fragment (you need NOT formally analyze) and how can you improve it further? [5] For size = 1 to n do For (left =1; left n-size+1; left++) do { right = left+size-1; M(left, right) = infinity; For (i = left; i right; i++) do { x = M(left, i) + M(i, right) + j=left right f j ; if x < min then M(left, right) = x }}; The summation needs a loop resulting in 4-loops O(n^4) complexity. The summation need not be inside the last loop. Two O(n^3) loops, when you take it outside the innermost loop – complexity is O(n^3). 2a.
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.

Page1 / 3

AlgGradFall06Fnl - Algorithms CSE 5211 Fall 2006 Final Exam...

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