{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# ps6 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

MIT OpenCourseWare http://ocw.mit.edu 6.00 6 Introduction to Algorithms Spring 200 8 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .

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

View Full Document
Introduction 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 define 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 ps6_fib.zip . (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 fib.py to the class website.
2 Handout 12: Problem Set 6 2. (15 points) Making Change You’ve just signed up as a software engineer for a new intergalactic trading post in Deep Space 6. For each transaction, you are given a list of coin denomination values, e.g., denomination = [1 , 5 , 10 , 17], and an amount of change, C . You have

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.

{[ snackBarMessage ]}

### Page1 / 5

ps6 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

View Full Document
Ask a homework question - tutors are online