ps6 - MIT OpenCourseWare http:/ 6.006...

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

View Full Document Right Arrow Icon
MIT OpenCourseWare 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: .
Background image of page 1

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

View Full DocumentRight Arrow Icon
to Algorithms: 6.006 Massachusetts Institute of Technology April 24, 2008 Professors Srini Devadas and Erik Demaine Handout 12 Problem Set 6 This problem set is due Thursday May 8 at 11:59PM . Solutions should be turned in through the course website in PDF form using L A T E X or scanned handwritten solutions. A template for writing up solutions in L A T E X is available on the course website. Remember, your goal is to communicate. Full credit will be given only to the correct solution which is described clearly. Convoluted and obtuse descriptions might receive low marks, even when they are correct. Also, aim for concise solutions, as it will save you time spent on write- ups, and also help you conceptualize the key idea of the problem. 1. (10 points) Fibonacci We de±ne the Fibonacci numbers as follows: F 0 = 0 F 1 = 1 n > 1 ,F n = F n 1 + F n 2 For this problem, you will code four versions of fib(n) , all of which should return the same answers. Download . (a) Write fib_recursive(n) . It should implement the recursion directly and take time exponential in n . (b) Write fib_memoize(n) . It should be recursive like fib_recursive(n) , but it should memoize its answers, so that it runs in time O ( n ). (c) Write fib_bottom_up(n) . Instead of working top-down like in the previous two examples, start from the bottom, recording your results in a list. This code should also take O ( n ) time. (d) Write fib_in_place(n) . It should work bottom-up like the previous example, but use only O (1) space instead of accumulating answers into a list. Submit
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

ps6 - MIT OpenCourseWare http:/ 6.006...

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

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