Massachusetts Institute of Technology
Dept. of Electrical Engineering and Computer Science
Spring Semester, 2008

6.01: Introduction to EECS 1
Programming Self-Diagnostic
Test Questions

Print out your answers hand them in at the EECS Undergraduate Office (38-476) sometime between Dec. 1 and Spring Registration Day.

For the programs (part 2 of the test) make sure to turn in your code together with a few test case results to demonstrate that the code runs.

Actually print out your answers and hand them in at the undergraduate office. Do not email them to us. Make sure that the pages of your work are stapled together.

In addition to this test to be handed in, there will be a short on-line questionnaire for students who will be taking the class. We will send email about this in mid-January.

Part 1: Your background; section preference — To do online now

This part should be done using the 6.01 on-line tutor, which you will also be using for homework problems during the semester.

Please visit the tutor login page at sicp.csail.mit.edu/6.01/ This will ask you to register for an account. After you register, the tutor will mail you a password that you can use to log in.

Log in and select "choose a problem set". "Problem set" 1 is a short survey to fill out. Please do this now.

Note: The tutor for this survey, and for doing 6.01 homework during the semester, is a different tutor from the one we're making available for optional Python programming practice during IAP. That programming practice tutor is at sicp.csail.mit.edu/6.01/progSp08/. The two tutor programs are completely separate; if you use both of them, you'll need to register for each one individually.

Part 2: Programming problems to write up and hand in

You should try to answer these problems, even if you can give only partial answers. If you can't make any progress at all -- for example, you have no prior programming experience and don't know where to begin -- just write "can't do this" as your answer to the problem.

Problem P2-A

(a) Write a procedure that solves quadratic equations using the quadratic formula: It should take as arguments three numbers a, b, and c. It should print error messages if a is zero, or if the roots are complex. Otherwise it should print the two roots. (b) Modify your procedure to handle the case of complex roots.

Problem P2-B

Write a procedure that evaluates polynomials. It should take two arguments. The first is a number . The second is a list of of coefficients ordered from highest to lowest:

Your procedure should return the value of the polynomial evaluated at :

Problem P2-C

A clerk works in a store where the cost of each item is a positive integer number of dollars. So, for example, something might cost $21, but nothing costs $9.99. In order to make change a clerk has an unbounded number of bills in each of the following denominations: $1, $2, $5, $10, and $20. Write a procedure that takes two arguments, the cost of an item and the amount paid, and prints how to make change using the smallest possible number of bills.

Problem P2-D

(a) Write a procedure that takes a string of words separated by spaces (assume no punctuation or capitalization), together with a "target" word, and shows the position of the target word in the string of words. For example, if the string is:

we dont need no education we dont need no thought control no we dont
and the target is the word "dont" then your procedure should return the list 1, 6, 13 because "dont" appears at the 1st, 6th, and 13th position in the string. (We start counting positions of words in the string from 0.) Your procedure should return False if the target word doesn't appear in the string.

(b) Suppose you are repeatedly looking up targets in a fixed long list. It might help to build an "inverted index", that shows the positions of all targets, so that this information can be retrieved quickly. For example, an inverted index for the above string of words would be:

we: 0, 5, 12
dont: 1, 6, 13
need: 2, 7
no: 3, 8, 11
education: 4
thought: 9
control: 10

Use an appropriate data structure to represent an inverted index. Write a procedure that, given a string of words, constructs an inverted index, and show how to use the index to look up target words as in part (a).

Back to info on this diagnostic