6.006 | Fall 2011 | Undergraduate

Introduction to Algorithms

Syllabus

Course Meeting Times

Lectures: 2 sessions / week, 1 hour / session

Recitations: 2 sessions / week, 1 hour / session

Course Description

This course provides an introduction to mathematical modeling of computational problems. It covers the common algorithms, algorithmic paradigms, and data structures used to solve these problems. The course emphasizes the relationship between algorithms and programming, and introduces basic performance measures and analysis techniques for these problems.

Prerequisites

A firm grasp of Python and a solid background in discrete mathematics are necessary prerequisites to this course. You are expected to have mastered the material presented in 6.01 Introduction to EECS I and 6.042J Mathematics for Computer Science.

If you have not taken and been successful in each of these subjects, please speak with a TA or professor before enrolling. We do allow students who have equivalent, other experience with the material described above to enroll, but with the firm understanding that mastery of this material is assumed and that course staff will not feel obligated to cover it or to help students who are struggling with it.

6.006 is a 12-unit (4-0-8) subject and serves as a Foundational Computer Science subject under the new curriculum. It is a direct prerequisite for 6.046 Design and Analysis of Algorithms, the theory header.

Textbooks

Required

Buy at MIT Press Cormen, Thomas, Charles Leiserson, Ronald Rivest, and Clifford Stein. Introduction to Algorithms. 3rd ed. MIT Press, 2009. ISBN: 9780262033848.

For the student who finds books helpful, we also suggest:

Miller, Bradley, and David Ranum. Problem Solving with Algorithms and Data Structures Using Python. 2nd ed. Franklin, Beedle & Associates, 2011. ISBN: 9781590282571.

Software

6.006 programming environment setup

Lectures and Recitations

One-hour lectures are held twice a week. You are responsible for material presented in lectures, including oral comments made by the lecturer (or other information that may not be present in the notes).

One-hour recitations are held twice a week, one day after the lectures. You are responsible for the material presented in recitation, which may include new material not presented in lectures. Recitation attendance has been well-correlated with quiz performance in past semesters. Recitations also give you a more intimate opportunity to ask questions of and to interact with the course staff. Your recitation instructor is responsible for determining your final grade.

Problem Sets

We will assign seven problem sets during the course of the semester. Each problem set will consist of a programming assignment, to be completed in Python, and a theory assignment.

If you collaborate with others in any fashion, you must list their names as collaborators. For details, please see the section on our collaboration policy; we take this very seriously.

Late assignments will be severely penalized. (This penalty is currently a 1% deduction every six minutes or part thereof until the end of the tenth hour after the deadline, after which submissions will receive no credit.)

Quizzes

We will give two evening quizzes during the semester; these will each be two hours in duration. There will also be a final exam during finals week.

Grading Policy

Your final grade will be determined by the grades you receive on problem sets, on quizzes, and on the final. The particulars of this policy are subject to the discretion of the course staff.

ACTIVITIES PERCENTAGES
Problem sets 30%
Quizzes 20% each
Final exam 30%

Coding Assignments

The code that you hand in will be graded based on its correctness, its quality, and the details of the algorithm that it implements.

Correctness

We will provide a set of public unit tests with each problem to help you test your work. However, when grading, we will use additional unit tests that will not be available to you; we reserve the right to test any behavior specified by or following from the problem statement. Submissions that run for excessive amounts of time may be scored as incorrect.

Theory

Code should represent an implementation of an appropriately designed algorithm. While we do not necessarily expect you to achieve any lower bounds that may exist for a particular problem, submissions should not be overly inefficient in either time or space.

Copying another student’s code is considered cheating. We may use both manual and automated methods to detect cheating.

Written Assignments

We expect you to enter proofs using LaTeX math mode directly into Gradetacular. We have a two-step process for grading proofs. First, you’ll enter your proof into Gradetacular before the time that the problem set is due. We will provide the solutions 10 hours after the problem set is due, which you will use to find any errors in the proof that you submitted. Your critique will usually be due by the following lecture. Your grade will be based on your solution and your critique.

The same late policy applies to the grading part of the assignment (1% off every six minutes that the problem set is late). Please note that if you require an extension, we will need to know in advance and you must have a good reason for needing it. In addition, we trust that you will not look at the posted solutions when completing the problem set under an extension. Looking at the solutions under these conditions constitutes a breach of the honor code, and is a serious offense.

The best responses will be concise, correct, and complete. Failing to answer part of the question, being overly verbose, missing special or edge cases, and answering mistakenly will each reduce your score.

When you are called upon to “give an algorithm,” you must provide (1) a textual description of the algorithm, and, if helpful, pseudocode; (2) at least one worked example or diagram to illustrate how your algorithm works; (3) a proof (or other indication) of the correctness of the algorithm; and (4) an analysis of the time complexity (and, if relevant, the space complexity) of the algorithm.

Remember that, above all else, your goal is to communicate. After all, if a grader cannot understand your solution, they cannot give you any credit for it.

Collaboration Policy

The goal of homework is to give you practice in mastering the course material. Consequently, you are encouraged to collaborate on problem sets. In fact, students who form study groups generally do better on exams than do students who work alone. If you do work in a study group, however, you owe it to yourself and your group to be prepared for your study group meeting. Specifically, you should spend at least 30–45 minutes trying to solve each problem beforehand.

You must write up each problem solution by yourself without assistance, even if you collaborate with others to solve the problem. You are asked on problem sets to identify your collaborators. If you did not work with anyone, you should write that you did not have collaborators. If you obtain a solution through research (e.g., on the web), acknowledge your source, but write up the solution in your own words. It is a violation of this policy to submit a problem solution that you cannot orally explain to a member of the course staff.

Code you submit must also be written by yourself. You may receive help from your classmates during debugging. Don’t spend hours trying to debug a problem in your code before asking for help. However, regardless of who is helping you, only you are allowed to make changes to your code. Both manual and automatic mechanisms will be employed to detect plagiarism in code.

No other 6.006 student may use your solutions; this includes your writing, code, tests, documentation, etc. It is a violation of the 6.006 collaboration policy to permit anyone other than 6.006 staff and yourself to see your solutions to either theory or code questions.

Plagiarism and other anti-intellectual behavior cannot be tolerated in any academic environment that prides itself on individual accomplishment. If you have any questions about the collaboration policy, or if you feel that you may have violated the policy, please talk to one of the course staff. Although the course staff is obligated to deal with cheating appropriately, we often have the ability to be more understanding and lenient if we find out from the transgressor himself or herself rather than from a third party.

This course makes use of Athena, MIT’s UNIX-based computing environment. OCW does not provide access to this environment.

This section covers the 6.006 programming environment setup:

CPython 2.7    
PyPy    
PIP    
IDEs / Code Editors    
PyDev in Aptana Studio

Overview

In theory, you can solve all the 6.006 assignments with nothing other than Notepad. However, in order to be efficient and make the most out of the class, you’ll need a plethora of software, such as a Python interpreter, the PIP package manager, and an IDE. You can find this software on Athena, which is the only platform that we officially support. The rest of this document will help you set up this software on your own machine. We have provided instructions below for the following operating systems / distributions:

  1. Ubuntu Linux 11.04 or 11.10
  2. Mac OS X 10.7 (Lion)
  3. Windows 7

Note on Windows Support

Windows is tricky to support because it does not obey standards such as POSIX out of the box, and we don’t use it for development. The course staff will attempt to help you with problems on Windows for the purpose of completing all the assignments, but please note that none of us use it on our own computers.

Python

We will test your code against the CPython 2.7 and PyPy interpreters. Reasonable code should behave identically in CPython and PyPy, but we sometimes use PyPy for performance reasons. You should develop under CPython, and only use PyPy if some weird issue arises. This document walks you through installing both flavors.

CPython 2.7

Ubuntu Linux

Run the following command in a Terminal window:    
sudo apt-get install -y python2.7 python-profiler

Python 2.7 should now be installed. Run python --version to make sure that the version is 2.7.

Mac OS X

We support the Python interpreter that comes with OS X 10.7 (Lion).

If you have OS X 10.6 (Snow Leopard), this Python 2.7.2 package (DMG) will most likely get you through the class, although the course staff will be unable to help you if you get stuck.

Windows 7

  1. Download Python 2.7.2 (MSI) and follow the wizard to install into the default location (C:\Python27\)
  2. Add Python to the PATH
    1. Go to Start → Control Panel → System and Security → System
    2. On the left, click on Advanced system settings
    3. Make sure you’re on the Advanced tab, and click on the Environment Variables button
    4. In the top list, find the PATH entry and click on it. Then, click the Edit… button.
    5. Append the following to the end of the entry (semicolon, spacing, and quotes matter; use the folder where you installed Python instead if you didn’t use the default):    
      ;"C:\Python27"
    6. If you had any open command prompt windows, close and reopen them so that they reflect the PATH change.

PyPy

Ubuntu Linux

  1. Download a Linux binary from the PyPy download page.
  2. Unpack it in the Downloads folder by double-clicking on the package.
  3. Open a Terminal window, and type the following commands:
  4. Install a required library:    
    sudo apt-get install libssl0.9.8
  5. Move pypy to a different location:    
    sudo mv ~/Downloads/pypy-1.6 /usr/local/pypy
  6. Make a symlink to pypy    
    sudo ln -s /usr/local/pypy/bin/pypy /usr/local/bin/pypy

You should now be able to run PyPy by typing pypy, unless you removed /usr/local/bin from your PATH.

Mac OS X

  1. Download PyPy 1.6 for OS X (TAR).
  2. Unpack it in the Downloads folder by double-clicking on the package.
  3. Open a Terminal window, and type the following commands:
  4. Move PyPy to a different location:    
    sudo mv ~/Downloads/pypy-1.6 /usr/local/pypy
  5. Make a symlink to pypy    
    sudo ln -s /usr/local/pypy/bin/pypy /usr/local/bin/pypy

You should now be able to run PyPy just type typing pypy, as /usr/local/bin should be in your PATH.

Windows 7

  1. Download PyPy 1.6 for Windows (EXE).
  2. Extract the zip file to C:\pypy-1.6-win32-c
  3. The main executable is C:\pypy-1.6-win32-c\pypy-c.exe

PIP

Make sure you have Python and PyPy installed before installing pip.

Ubuntu Linux

You can test whether you were able to install pip for PyPy correctly by running pypy-pip install pygments and then running pypy and trying to import pygments. If it succeeds, and pygments.__version__ looks like a version number, then you’ve installed PIP successfully. Do the same with pip for CPython by running sudo pip install pygments and then running python and trying to import pygments. Then check the pygments version again.

Mac OS X

You can test whether you were able to install pip for PyPy correctly by running pypy-pip install pygments and then running pypy and trying to import pygments. If it succeeds, and pygments.__version__ looks like a version number, then you’ve installed PIP successfully. Do the same with pip for CPython by running pip install pygments and then running python and trying to import pygments. Then check the pygments version again.

Windows 7

  1. Download and install setuptools for Python 2.7.
  2. Add the Scripts folder to the PATH
    1. Go to Start → Control Panel → System and Security → System
    2. On the left, click on Advanced system settings
    3. Make sure you’re on the Advanced tab, and click on the Environment Variables button
    4. In the top list, find the PATH entry and click on it. Then, click the Edit… button.
    5. Append the following to the end of the entry (semicolon, spacing, and quotes matter; use the folder where you installed Python instead if you didn’t use the default):    
      ;"C:\Python27\Scripts"
    6. If you had any open command prompt windows, close and reopen them so that they reflect the PATH change.

Open a new command prompt window and type easy_install pip    
If this step fails, make sure you edited the PATH correctly in the previous step. For some students, leaving out the quotes (i.e. adding ;C:\Python27\Scripts to the PATH) worked better.

pip should now be installed for CPython. You can test it by opening a command prompt window and running pip install pygments, then running python and checking that import pygments doesn’t fail and that pygments.__version__ looks like a version number.

Now, install pip for PyPy:

  1. Download these two files to C:\pypy-1.6-win32-c\pypy-1.6 (or wherever else you installed PyPy). If they open in your browser, you can typically go to the File menu and choose Save File As… to save them to your desired location (in this case, the PyPy folder).    
    Get distribute_setup.py    
    Get get-pip.py
  2. Open a new command prompt window, and change directories to your PyPy folder:    
    cd C:\pypy-1.6-win32-c\pypy-1.6
  3. Run the following commands to install pip for PyPy:    
    pypy-c distribute_setup.py   
    pypy-c get-pip.py

pip should now be installed for PyPy in C:\pypy-1.6-win32-c\pypy-1.6\bin. You can test it by opening a command prompt window and running C:\pypy-1.6-win32-c\pypy-1.6\bin\pip install pygments, then running C:\pypy-1.6-win32-c\pypy-1.6\pypy-c and checking that import pygments doesn’t fail and that pygments.__version__ looks like a version number.

IDEs / Code Editors

An IDE (Integrated Development Environment) can help you develop Python programs more efficiently.

IDLE comes with Python, and is a good default choice. IDLE is installed by default on Windows and Mac OS X. On Ubuntu, you can install it with the following command: sudo apt-get install idle

PyDev in Aptana Studio

Ubuntu Linux

  1. Launch Software Sources from the Ubuntu Menu. Select the Other Software tab, then select the Canonical Partners repositories. Close the dialog when done.
  2. Open a Terminal window.
  3. Update your software cache.    
    sudo apt-get update
  4. Install the prerequisite software.    
    sudo apt-get install -y sun-java6-jdk sun-java6-fonts ant ant-optional   
    libglade2-0 libgnome2-0 libgnomecanvas2-0 libgnomecanvas2-common   
    libgnomeui-0 libgnomeui-common sat4j git
  5. Download Aptana Studio and extract it in your home directory.

Mac OS X

Download and install Aptana Studio.

Windows

  1. Download the latest version of the Java SE 6 JDK.
  2. Download and install Aptana Studio.

Course Info

Learning Resource Types
Lecture Videos
Recitation Videos
Problem Sets with Solutions
Exams with Solutions
Programming Assignments with Examples
Lecture Notes