This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS61A: Midterm #2--Spring 1995 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 '()) (make-node 7 '()) file:///C|/Documents%20and%20Settings/Jason%20Raft...20Spring%201995%20-%20Clancy%20-%20Midterm%202.htm (1 of 4)1/27/2007 4:08:28 PM CS61A: Midterm #2--Spring 1995...
View Full Document
- Spring '08
- Computer Science, Return statement, Abelson