CS61A_sp04_f - CS 61A, Spring, 2004, Final, Harvey Question...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A, Spring, 2004, Final, Harvey Question 1 (2 points): Circle TRUE or FALSE : Normal and applicative order of evaluation give the same result if there's no assignment ( set! ) or mutation ( set-car!, set-cdr! ). Question 2 (6 points): (a) The following procedure takes one argument, a nonempty list of words (define (mystery list-of-words) (let ((pairs (map (lambda (x) (cons (count x) x)) list-of-words))) (cdr (accumulate (lambda (x y) if (> (car x) (car y)) x y )) (car pairs) (cdr pairs))))) In 20 words or less, what does mystery return? (b) Write a procedure maximizer that takes one argument, which is a one-argument function fun whose range is numbers. Maximizer should return a function like mystery , but using fun to measure of the elements of the list. Question 3 (4 points): Consider the following procedure: (define (repetitions sent) (define (reps s num) (cond ((= num 0) '()) ((empty? s) (reps sent num)) (else (se (first s) (reps (bf s) (- num 1)))))) (reps sent 5)) (a) Fill in the proper return values: > (repetitions '(hello there)) __________________________________________ > (repetitions '(in the white room with black curtains)) __________________________________________ (b) Circle TRUE or FALSE : The time required for repetitions grows linearly with the size of its argument sent . Question 4 (4 points): A database company is using trees to store sentences, using the Tree abstract data type:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(define make-tree cons) (define datum car) (define children cdr) These trees are becoming too large, and in an effort to reduce memory usage the database programmers decide to store only the first word of the sentence in each datum. Below is a procedure that is designed to search through one of these trees of sentences and return a new tree with just the first word of each sentence. As an example, calling reduce-tree on the following tree: (Holidays of the United States) / | \ / | \ (NewYear Jan 1) (Independence July 4) (Veterans Nov 11) / | \ / | \ (Christmas Dec 25) (Memorial May Last Monday) (Labor Sep First Monday) results in smaller memory reduced tree: Holidays / | \ / | \ NewYear Independence Veterans / | \ Christmas Memorial Labor There are some data abstraction violations in the code for reduce-tree and its helper reduce-forest . Circle them and write the correct selector or constructor below the error. (define (reduce-tree tree) (cons (car (car tree)) (reduce-forest (cdr tree)))) (define (reduce-forest forest) (if (null? forest) '() (cons (reduce-tree (car forest)) (reduce-forest (cdr forest))))) Question 5 (6 points): For this question we're introducing a new kind of tree in which data are all numbers. This kind of tree
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2010 for the course CS 61A taught by Professor Harvey during the Fall '08 term at University of California, Berkeley.

Page1 / 8

CS61A_sp04_f - CS 61A, Spring, 2004, Final, Harvey Question...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online