Sample Midterm Exam Questions for CISC 280 (The first two questions were of a type that I don't ask anymore.) 3. (10 pts.) What will be printed out when the following expressions are evaluated? (i) (let ((x '(a (b c) 1))) (display (cadr x)) (newline) (cddr x)) (ii) ((lambda (x y) (+ x y (* x y))) 2 3) (iii) (map (lambda (x y) (if (< x y) (* x y) (+ x y))) '(1 4 2 3) '(2 2 1 4)) 4. (10 pts.) Draw the box-and-pointer notation for the list structure that Scheme builds before evaluating the following expression: (define (fun x) (cond ((null? x) 1) ((pair? x) 2) (else 3))) 5. (25 pts.) Define a function that computes the average of a list of numbers. The number of numbers in the list is not known in advance. If there are no numbers in the list, produce an error message. You may only use numbers, variables and your choice of the following functions that are already defined in Scheme: define, car, cdr, cons, length, append, map, eq?, +, *, /, -, if, cond, =, not, let, lambda, error, else, null?, pair?. 6. (25 pts.) Define a function called triple that takes a function f as input and returns a function that will evaluate to three times what f would have produced. For example, if (f 4) evaluates to 17, ((triple f) 4) will evaluate to 51. 7. (10 pts.) What is the order of complexity of the following functions? (i) (define (trouble lst) (map (lambda (x) (cons x lst)) lst)) (ii) (define (more-trouble lst) (map (lambda (x) (append lst (list x))) lst)) (iii) (define (trouble-again n) (if (< n 1) 1 (+ n (trouble-again (/ n 2)))))