{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

H02-ps1

# H02-ps1 - Introduction to Algorithms 6.006 Massachusetts...

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

Introduction to Algorithms: 6.006 Massachusetts Institute of Technology February 3rd, 2009 Professors Sivan Toledo and Alan Edelman Handout 2 Problem Set 1 This problem set is divided into two parts: Part A problems are programming tasks, and Part B problems are theory questions. Part A questions are due Tuesday, February 17th at 11:59PM . Part B questions are due Thursday, February 19th 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. Part A: Due Tuesday, February 17th 1. (20 points) Running Time Version 6 of our Document Distance code uses an algorithm called merge sort to improve upon the Θ( n 2 ) running time of insertion sort. (We’ll talk more about merge sort and other sorting algorithms in a few weeks.) You can ﬁnd an implementation of merge sort on page 3 of this document. (a) (10 points) Determine experimentally the running time of mergesort, by run- ning it on different-sized lists of random numbers. (After you import random , you can get a random ﬂoating-point number using the random.random() function.) Fill in the following chart. Include in your PDF submission a snippet of code that determines one of the entries in the chart. | s | = 10 2 | s | = 10 3 | s | = 10 4 | s | = 10 5 time in ms There are a number of ways to time code. You can use the timeit module 1 Al- ternatively, if you have ipython installed, 2 you can use the more user-friendly builtin %timeit command. Make sure you check what the default number of iterations for your timing command is! By default, Timer.timeit() in the 1 See http://www.diveintopython.org/performance_tuning/timeit.html

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 / 6

H02-ps1 - Introduction to Algorithms 6.006 Massachusetts...

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

View Full Document
Ask a homework question - tutors are online