|
Projects
Spring 2012 Older Courses Fall 2011 Spring 2011 Fall 2010 Spring 2010 Fall 2009 Spring 2009
Fall 2008
Spring 2008
Fall 2007 HOWTOs |
OPLspr09 /
PS3Home Assignments Lecture Blog Resources Project Discussion Group 91.301 Organization of Programming Languages Out: Feb 9, 2009 Problem Set 3: Data Abstractions & Data StructuresScheme Settings
What to turn in
ReadingSICP reading: Sections 2.1 through 2.2.2. The Exercises1. 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,
(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
(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 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 Honors, Grad Students, and Extra Credit9. Solve SICP exercise 2.27 on Please don't just turn in the answerthat won't be credible. Show how you got there; or if you don't fully solve it, how far you got. |