Recent Changes - Search:

Home

Is the Laser up?

People

Publications

Calendar

Projects

Spring 2012

Older Courses

Fall 2011

Spring 2011

Fall 2010

Spring 2010

Fall 2009

Spring 2009

Fall 2008

Spring 2008

Fall 2007

HOWTOs

edit SideBar

PS3

Home Assignments Lecture Blog Resources Project Discussion Group

91.301 Organization of Programming Languages
Prof. F. Martin

Out: Feb 9, 2009
Due: Feb 17, 2009

Problem Set 3: Data Abstractions & Data Structures

Scheme Settings

  • Use the Module language in DrScheme
  • You should define nil as follows in your evaluation buffer: (define nil '())

What to turn in

  • Keep your answers in a file named ps3-ans.scm.
  • Put your name at the top of the file in a comment block.
  • Put the code for each problem sequentially in the definitions buffer.
  • Put the problem number in a comment before the code for that problem (use a semi-colon to make a line a comment). Underneath the code for each problem, cut and paste the appropriate sample runs. You can put semi-colons in front of the sample runs, which will comment them out and allow you to load the entire buffer in another session.
  • If you have any hand-written content, turn it in at the beginning of class on the due date. Submit code electronically.
  • Submit your answer buffer using the submit command on Mercury: submit fredm 301-ps3 ps3-ans.scm

Reading

SICP reading: Sections 2.1 through 2.2.2.

The Exercises

1. SICP exercise 2.2 (pp. 89-90). In this problem you create data structures in Scheme representing line segments in a plane.

2. SICP exercise 2.3 (pp. 90). Here you represent rectangles and construct procedures to compute perimeter and area.

3. For each of the following definitions,
a. Draw the box and pointer diagram
b. Give the sequence of cars and cdrs needed to return the number 4


      (define a (list 1 2 3 4))
      (define b (cons (cons 3 4) (cons 5 6)))
      (define c (list 1 (list 2 3) 4))

4. Draw a box and pointer diagram for each of the lists d, e and f defined as follows:


      (define d (list 1 2))
      (define e (cons d d))
      (define f (append d d))

What would be printed by Scheme when asked for the values of d, e and f sequentially?

5. Consider the following recursive procedure:


    (define (list-prod lst) 
        (if (null? lst) 
           1 
           (* (car lst) 
              (list-prod (cdr lst))))) 

a) How many times is list-prod called when evaluating the expression (list-prod '(1 2 3 4)) ?
b) What is the order of growth in space and time for the list-prod procedure above?
c) Write an iterative version of the procedure list-prod.
d) What is the order of growth in space and time for your iterative list-prod procedure from part c?

6. Write a procedure called double-list in three different ways:

a) Write a list manipulation procedure of your own to do this.
b) Use the scale-list procedure on pp. 105 in your definition.
c) Use the map procedure on p. 105 in your definition.

7. SICP exercise 2.20 (pp. 104), on the dotted-tail notation.

8. SICP exercise 2.21 (pp. 106), on square-list.

Honors, Grad Students, and Extra Credit

9. Solve SICP exercise 2.27 on deep-reverse. Note: it will be easy enough to Google for the answer on this. Obviously this will short-circuit your learning. So don't do that, and instead please show steps along the way to your solution—e.g., partly working code, what inputs you tested it on, what results it produced, what you did next.

Please don't just turn in the answer—that won't be credible. Show how you got there; or if you don't fully solve it, how far you got.

Edit - History - Print - Recent Changes - Search
Page last modified on February 15, 2009, at 10:17 PM