CS61A_sp95_mt2 - CS61A: Midterm #2-Spring 1995 CS61A,...

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

View Full Document Right Arrow Icon
CS61A, Spring 1995 Midterm #2 Question 1 (2 points): What will Scheme print in response to the following expressions? Also, draw a ``box and pointer'' diagram for the result of each expression: (cddaar '(((a b c d e) (f g h i j)) ((l m n o p) (q r s t u)))) (cons '(a b) (append '(c d) '(e f))) Question 2 (2 points): Each of the following expressions, when evaluated, returns a list. Identify the type (e.g., procedure, non-numeric word, list, number) of the last element in each of the lists. '(list (count 'hello)) '(list count) (list 'count count) (list 'hello (count 'hello)) Question 3 (5 points): This question concerns the tree abstract data type, as defined by these selectors and constructor: (define datum car) (define children cdr) (define make-node cons) Write the higher-order procedure tree-accumulate . Its two arguments are a function fn and a tree. The function fn will take two arguments and will be associative. (That is, you don't have to worry about the order in which you find the nodes in the tree.) Tree-accumulate will combine all of the datum elements in the tree by applying fn to them two at a time, analogous to ordinary accumulate . For example: > (define my-tree (make-node 3 (list (make-node 4 '())
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 / 3

CS61A_sp95_mt2 - CS61A: Midterm #2-Spring 1995 CS61A,...

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

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