This exam is worth 30 points, or about 28% of your total course grade. The exam contains

Similar documents
CS 61A Midterm #2 - October 5, 1998

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

Discussion section number. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z

CS 61A Midterm #2 ver March 2, 1998 Exam version: A. Your name. login: cs61a- Discussion section number. TA's name

This exam is worth 60 points, or 30% of your total course grade. The exam contains eight


This exam is worth 30 points, or 18.75% of your total course grade. The exam contains

This exam is worth 40 points, or 30% of your total course grade. The exam contains eight

CS 275 Name Final Exam Solutions December 16, 2016

A random five-digit number: a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3

User-defined Functions. Conditional Expressions in Scheme

Scheme Basics > (butfirst '(help!)) ()

HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other?

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g))

This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

CSE413 Midterm. Question Max Points Total 100

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Write a procedure powerset which takes as its only argument a set S and returns the powerset of S.

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014


Structure and Interpretation of Computer Programs

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Structure and Interpretation of Computer Programs

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CSE341 Autumn 2017, Final Examination December 12, 2017

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

Racket Style Guide Fall 2017

CSL 201 Data Structures Mid-Semester Exam minutes

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

ElseIf: Another Conditional Statement

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

CS 314 Principles of Programming Languages. Lecture 16

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Department of Electrical Engineering and Computer Sciences Fall 2000 Instructor: Dan Garcia CS 3 Final Exam

Structure and Interpretation of Computer Programs

6.001, Spring Semester, 1998, Final Exam Your Name: 2 Question 1 (12 points): Each of the parts below should be treated as independent. For each part,

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Discussion 4. Data Abstraction and Sequences

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

CSE341 Spring 2017, Final Examination June 8, 2017

The temporal explorer who returns to the base 1

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20

mk-convert Contents 1 Converting to minikanren, quasimatically. 08 July 2014

CS115 - Module 10 - General Trees

CSE341 Spring 2017, Final Examination June 8, 2017

CSE 341 : Programming Languages Midterm, Spring 2015

CS 2150 (fall 2010) Midterm 2

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

CS61A Midterm 2 Review (v1.1)

6.001 Notes: Section 8.1

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

6.001 Notes: Section 6.1

Warm-up and Memoization

CS61A Notes Disc 11: Streams Streaming Along

Part I Introduction: Functions

Project 5 - The Meta-Circular Evaluator

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

CS 415 Midterm Exam Spring SOLUTION

CS 245 Midterm Exam Winter 2014

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

CSc 520. Principles of Programming Languages 7: Scheme List Processing

CS 415 Midterm Exam Spring 2002

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

YOUR NAME PLEASE: *** SOLUTIONS ***

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

CS2500 Exam 2 Fall 2014

Overview. CS301 Session 3. Problem set 1. Thinking recursively

MIDTERM EXAMINATION - CS130 - Spring 2005

6.001 Notes: Section 15.1

CSc 520 Principles of Programming Languages. Examining Lists. Constructing Lists... 7: Scheme List Processing

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

A Small Interpreted Language

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

Structure and Interpretation of Computer Programs

A Second Look At ML. Chapter Seven Modern Programming Languages, 2nd ed. 1

CSC 207 (16fa) Practice Exam 2 Page 1 of 13. Practice Exam 2 (Exam 2 date: Friday 11/18) Logistics:

Functional Programming. Pure Functional Languages

CS 314 Principles of Programming Languages

Question 1 (2 points): In project 1 we told you that you didn'thave to turn o interrupts in your implementation of semaphores, but in project 2 we tol

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

John McCarthy IBM 704

Why do we need an interpreter? SICP Interpretation part 1. Role of each part of the interpreter. 1. Arithmetic calculator.

COMP 105 Homework: Type Systems

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Well, Hal just told us how you build robust systems. The key idea was-- I'm sure that many of

CS 360 Programming Languages Interpreters

University of California, Berkeley College of Engineering

Structure and Interpretation of Computer Programs

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

Transcription:

CS 3 Final May 16, 1994 Your name login cs3{ This exam is worth 30 points, or about 28% of your total course grade. The exam contains eight questions. This booklet contains eight numbered pages including the cover page. Put all answers on these pages, please don't hand in stray pieces of paper. This is an open book exam. When writing functions, write straightforward code. Do not try to make your program slightly more ecient at the cost of making it impossible to read and understand. When writing procedures, don't put in error checks. Assume that you will be given arguments of the correct type. Our expectation is that many of you will not complete one or two of these questions. If you nd one question especially dicult, leave it for later start with the ones you nd easier. 1 =3 2 =3 3 =4 4 =4 5 =4 6 =4 7 =4 8 =4 1 total =30

Question 1 (3 points): What is the value of each of the following expressions? (If the expression's value is a procedure you may just write \procedure." If evaluating the expression would cause an error, just write \error.") > (caddar '((a b c d e f) (g h i j k l) (m n o p q r))) > (append (list '(a b) '(c d)) (cons '(e f) '(g h))) > (every (lambda (x) (item x '(a b c d e f g h))) 2514) > (keep (lambda (x) (even? (count x))) '(john paul george ringo)) > (leaf? (make-node '(a b) '())) > (filter (lambda (x) #t) '(back in the ussr)) 2

Your name login cs3{ Question 2 (3 points): Which of the following might be a sensible procedure argument to repeated with a numeric argument of 4? That is, for which of them will repeated return a function that can be applied to some argument without causing an error? (There may be more than one such procedure circle all of them.) cdr (lambda (x) (* x x)) cons even? random length Question 3 (4 points): Write a procedure middle that nds the middle word of a sentence. If the sentence has an even number of words, return the rst of the two middle ones. For example: > (middle '(got to get you into my life)) YOU > (middle '(your mother should know)) MOTHER 3

Question 4 (4 points): Write a procedure pairs-checker whose argument is a predicate function of two arguments. It should return a predicate function of one argument, a list, that returns true if the original predicate is true for every pair of consecutive elements in the list. For example: > (define increasing? (pairs-checker <)) > (increasing? '(4 23 72 95 100)) > (increasing? '(4 23 95 72 100)) #F > ((pairs-checker equal?) '(foo foo foo foo foo)) > ((pairs-checker equal?) '(foo foo foo foo baz baz)) #F 4

Your name login cs3{ Question 5 (4 points): Write a predicate function samepairs? that takes a list as its argument. It should return true if the same two values appear twice as consecutive elements of the list. For example: > (samepairs? '(a b x y c d e f x y g h)) > (samepairs? '(a b x y c d e f x g y h)) #F > (samepairs? '(a b x x x c d)) (In the third example, there are two overlapping x x pairs.) 5

Question 6 (4 points): Write a function max-children that takes a tree as its argument and returns the largest number of children that any node in the tree has. Use the tree abstraction, not \cheap" trees. For example, if world-tree is the tree illustrated on page 298 of the text, then > (max-children world-tree) 7 because the node with the largest number of children in this example is the root node, with seven children. 6

Your name login cs3{ Question 7 (4 points): You've seen in the spreadsheet example that vectors can have vectors as elements. Those sub-vectors might themselves have sub-sub-vectors as elements, and so on. Write a predicate vector-deep-member? that takes two arguments, the rst of which is any value and the second of which is a vector, possibly including subvectors. The predicate should return true if its rst argument isamember of the vector, or a member of a member, etc. > (vector-deep-member? 3 #(4 #(27 92) #(3 #(7 15 4) 9) 8 #(2 5))) 7

Question 8 (4 points): Note: This is a hard question! We expect that many peoplewon't solve it. Think about a predicate function of several Boolean arguments, made up of some composition of and, or, and not, like these examples: (define (fun p q r s t) (define (zot p q r s t) (and (or p q) (and (or p q) (not (or q r s)) (not (or q r s)) (and s t))) (and p t))) Such a predicate is called satisable if there is some combination of argument values that will make this function return. For example, the function fun is not satisable, because the argument called s would have to be false to satisfy (not (or q r s)) but would have to be true to satisfy (and s t), so those subexpressions can't both be true. But zot is satisable, because (zot #t #f #f #f #t) returns. Write a function satisfiable? whose two arguments are a predicate function such as the example described above and a number indicating how many arguments that function takes. Your function should return true if the argument function is satisable. For example: > (satisfiable? fun 5) #F Hint: Create all possible combinations of Boolean argument values. 8