CS 3L (Clancy) Solutions and grading standards for exam 1

Similar documents
Solutions and grading standards

Note that if both p1 and p2 are null, equals returns true.

8*4 + 4 = 36 each int is 4 bytes

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn

Solutions and grading standards

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 61B (Clancy, Yelick) Solutions and grading standards for exam 2 Spring 2001 Exam information

CS3 Fall 05 Midterm 1 Standards and Solutions

Read and fill in this page now. Your instructional login (e.g., cs3-ab): Your lab section days and time: Name of the person sitting to your left:

CS 170 Spring 2000 Solutions and grading standards for exam 1 Clancy

CS3 Midterm 1 Fall 2006

Read and fill in this page now

CS 61B, Midterm #3 and solutions, Spring 1996

CS3 Midterm 2 Standards and Solutions

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

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.

CS3 Midterm 1 Fall 2007 Standards and solutions

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)


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

CS143 Midterm Fall 2008

CS3: Introduction to Symbolic Programming. Lecture 5:

CS61BL Summer 2013 Midterm 2

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Project 5 - The Meta-Circular Evaluator

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

One of Mike s early tests cases involved the following code, which produced the error message about something being really wrong:

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Homework 4 Even numbered problem solutions cs161 Summer 2009

CS3 Midterm 2 Summer 2008

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

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Rational Numbers CHAPTER Introduction

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

6.001 Notes: Section 4.1

Only to be used for arranged hours. Order of Operations

Drawing Hands, by M. C. Escher (lithograph, 1948)

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

Section 1.1 Definitions and Properties

Notes and Answers to Homework Exam 1, Geometric Algorithms, 2017

We've tried to include the common errors and grading standard for every question.

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

Lecture 4 CSE July 1992

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

Final Exam Solutions May 11, 2012 CS162 Operating Systems

Use the Associative Property of Multiplication to find the product.

(Refer Slide Time 3:31)

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

(Refer Slide Time 6:48)

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

Midterm 2. Read all of the following information before starting the exam:

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division

Midterm 2 Solutions. CS70 Discrete Mathematics for Computer Science, Fall 2007

Fall 2010 CS61C Midterm 1 Solutions

CSc 372, Fall 2001 Final Examination December 14, 2001 READ THIS FIRST

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

CPS 310 midterm exam #1, 2/19/2016

Intro. Scheme Basics. scm> 5 5. scm>

Modesto City Schools. Secondary Math I. Module 1 Extra Help & Examples. Compiled by: Rubalcava, Christina

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

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

(the bubble footer is automatically inserted into this space)

The Interpreter + Calling Functions. Scheme was designed by people. The Interpreter + Calling Functions. Clickers. Parentheses Matter We asked scheme

Please write your name and username here legibly: C212/A592 6W2 Summer 2017 Early Evaluation Exam: Fundamental Programming Structures in Java

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

CSc 451, Spring 2003 Examination #1 February 25, 2003 READ THIS FIRST

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

CS 6353 Compiler Construction Project Assignments

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

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

CS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion

CS 111X - Fall Test 1

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018

When using computers, it should have a minimum number of easily identifiable states.

Chapter 0, Pre-Algebra from Beginning and Intermediate Algebra by Tyler Wallace is available under a Creative Commons Attribution 3.

CS 6353 Compiler Construction Project Assignments

This homework has an opportunity for substantial extra credit, which is described at the end of this document.

Beginning and Intermediate Algebra Chapter 0: Arithmetic

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

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Stating the obvious, people and computers do not speak the same language.

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

Style and Submission Guide

CS164: Midterm Exam 2

Computer Science Foundation Exam

Midterm #2 With Solutions solutions in blue marking notes in red

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

Types, Expressions, and States

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

CS 1301 Exam 1 Fall 2010

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008

University of California, Berkeley College of Engineering

CSE 123: Computer Networks

Transcription:

CS 3L (Clancy) Solutions and grading standards for exam 1 Fall 2009 *** DRAFT 177 students took the exam. We are still gathering statistics about the exam (mean and median). However, were you to receive grades of 75% on each in-class exam and on the final exam, plus good grades on homework and lab, you would receive an A ; similarly, a test grade of 21 may be projected to a B. There were four versions of the test. (The version indicator appears at the bottom of the first page.) If you think we made a mistake in grading your exam, describe the mistake in writing and hand the description with the exam to your lab t.a. or to Mike Clancy. We will regrade your entire exam. Problem 0 (2 points) Each of the following cost you 1 point on this problem: you earned some credit on a problem and did not put your login name on the page, you did not adequately identify your lab section, or you failed to put the names of your neighbors on the exam. The reason for this apparent harshness is that exams can get misplaced or come unstapled, and we want to make sure that every page is identifiable. We also need to know where you will expect to get your exam returned. Finally, we occasionally need to verify where students were sitting in the classroom while the exam was being administered. Problem 1 (6 points) In this problem, you were to evaluate the results of calls to a procedure named howbuilt: (define (how-built x) (sentence 'sentence (first x) (butfirst x)) ) Versions differed in the arguments used and the sequence of calls. Version A s answers are as follows. expression result (how-built '(a b c d)) (sentence a b c d) (how-built 'abcd) (sentence a bcd) (how-built '(a)) (sentence a) (how-built 'a) (sentence a "") The first two answers were worth 1 point each. The last two answers were worth 2 points each. Some special cases: 1 Omit parens or include quotes. 2 Omit sentence. 1 (sentence a ( )) instead of (sentence a). (Sentences can contain only words, not sentences.) The rationale for awarding partial credit is that at least the student knows what (butfirst '(a)) is. 1 (sentence a) instead of (sentence a ""). A

Problem 2 (5 points) This problem involved working with and rewriting a procedure named exam-proc. The four versions of exam-proc appear below. ; Version A ((not (member? x '(1 3 5 7 9))) #T) ((member? x '(2 3 4 5)) #F) (else #T) ) ) ; Version C ((not (member? x '(0 2 4 6 8))) #T) ((member? x '(2 3 4 5)) #F) (else #T) ) ) ; Version B ((not (member? x '(1 3 5 7 9))) #T) ((member? x '(4 5 6 7)) #F) (else #T) ) ) ; Version D In part a, you were to evaluate a call to exam-proc: version call ((not (member? x '(0 2 4 6 8))) #T) ((member? x '(4 5 6 7)) #F) (else #T) ) ) result A (exam-proc 3) #F B (exam=proc 9) #T C (exam-proc 2) #F D (exam-proc 8) #T This was worth 1 point; no partial credit was awarded. Part b involved converting the cond to a call to member?. To do this, one might test each of the ten values separately. A more efficient approach, however, might go like this (using version A): 0, 2, 4, 6, 8 all produce a true value. 3 and 5 produce a false value (2 and 4 were covered by the preceding case). What s left 1, 7, and 9 also return a true result. Thus the argument to member? is (0 1 2 4 6 7 8 9). Corresponding answers to versions B, C, and D are (0 1 2 3 4 6 8 9), (0 1 3 5 6 7 8 9), and (0 1 2 3 5 7 8 9) respectively. This part was worth 2 points. Common errors and corresponding deductions were as follows. You lost 1 point for forgetting about 0. Many students thought that some values left out of the sentence in the first cond clause 2 and 4 in version A, 4 and 6 in B, 3 and 5 in C, and 5 and 7 in D don t return true; instead, they thought that execution proceeded to the second clause and returned #f for these values. This lost you 2 points. 2

A similar misconception was that only values left out of both member? calls could return true: 6 and 8 for version A; 2 and 8 for B; 1, 7, and 9 for C; and 1, 3, and 9 for D. This was also a 2-point error. Finally, you were to rewrite exam-proc without using cond or if, making sure that it handles non-integer and out-of-range integer arguments the same as the original code (i.e., returns true). A version using the builtin integer? procedure is (or (not (integer? x)) (< x 0) (> x 9) (member? x your_answer_to_part_b )) ) Use of integer? turns out not to be necessary, however: (not (member? x single_digits_not_in_your_part_b_answer)) ) The argument to member? here is a sentence containing the two single-digit values for which exam-proc returns #F. In order not to dock you twice for the same part b error, we used your answer to part b to determine the argument to member?. This part was worth 2 points: 1 for correctly handling non-integers and 1 for correctly handling integers outside the range of 0 to 9. Problem 3 (6 points) This problem explored the effect of passing words as arguments to the version 1 day-span rather than sentences. One might expect that this would always cause a crash, but that s not necessarily the case. The procedures that access date information, month-name and date-in-month, each returns a character value for a word argument of two or more characters. Some of the procedures in the program manage to avoid crashing with character arguments. In part a, you analyzed a call that does produce a crash, and were asked to describe where and why the crash occurred. First, same-month? is called. It compares the first character of the first argument with the first character of the second argument. These match, so same-month? returns true. Then same-month-span is called. It subtracts the second character in the first argument from the second character in the second argument. The second argument in all the versions is a letter, which is an illegal argument for the subtraction procedure. This part was worth 2 points. A common error, earning a 1-point deduction, was to explain correctly how a error would occur in consecutive-months?. For part b, you had to fill in the blank with a word argument for which day-span would not crash. Continuing with the call to same-month-span, we see that any word whose first character matches that of the given argument and whose second character is a digit works. 3

You could earn 1 point for the answer and 3 points for the explanation in this part. A 1- point deduction resulted from assuming that date-in-month could return a two-digit value. Problem 4 (9 points) This problem was the same in all versions. It asked you to consider a calendar in which all the months with 31 days preceded all the months with 30 days, leaving a 28-day December at the end. In part a, you were to implement equal-length-month-span for this calendar, using procedures already defined in the version 1 code wherever possible. Here s a solution. (define (equal-length-month-span earlier-date later-date) (+ (days-remaining earlier-date) (date-in-month later-date) (* (days-in-month (month-name earlier-date)) (- (- (month-number (month-name later-date)) (month-number (month-name earlier-date)) ) 1) ) ) The calls to days-remaining and date-in-month can but need not be replaced by a single call to consec-month-span. Here's an equivalent version that uses samemonth-span; note in particular that it handles the case of a negative return value. (define (equal-length-month-span earlier-date later-date) (+ (* (days-in-month (month-name earlier-date)) (- (month-number (month-name later-date)) (month-number (month-name earlier-date)) ) ) (same-month-span earlier-date later-date) ) ) Finally, here is a version based on approach #2. (define (equal-length-month-span earlier-date later-date) (+ 1 (- (days-up-thru later-date) (days-up-thru earlier-date) ) ) ) (define (days-up-thru date) (+ (date-in-month date) (if (<= (month-number (month-name date)) 8) (* (- (month-number (month-name date)) 1) 31) (+ 217 (* (- (month-number (month-name date)) 8) 30) Note that you didn't need to make a special case for December. Any legal December date will have 28 or fewer days, so it does no harm to pretend that it has 30 days. 4

This part was worth 6 points. Some common deductions were the following. 1 Using first/butfirst instead of month-name and date-in-month, or treating 30 and 31 as two different but essentially equivalent cases instead of calling days-in-month. (You were told to use procedures already defined in the version 1 code wherever possible. Many students lost 1 or 2 points here.) However, you were not penalized for using a longer-than-necessary expression involving version 1 procedures, e.g. (+ 1 (- (days-in-month (month-name date)) (date-in-month date))) instead of (days-remaining date). 1 Off-by-one computation. 1 Forgetting to apply month-name to a date before passing it to month-number or days-in-month. 2 In the version based on approach #2, using a big cond instead of monthnumber and days-in-month. Missing parts of the computation lost you at least 2, for example, neglecting to count the contribution of the end months, or computing the number of intervening months, but forgetting to multiply the number of intervening months by the month length. (Not dealing with the intervening months at all lost you 4 points.) Part b was to explain why the revised association of months and days make it easier to finish the first version of the day-span code. The first version could not concisely determine the number of days between two arbitrary months. In the reorganized calendar, however, it can, because of the regularity of dates. In particular, the number of days in intervening months can be computed, either as we did it in part a or, in case the end months have different lengths, there will be some months of length 30 (up through July) and some of length 31 (August or later). Many of you lost 1 point by providing an explanation that assumed that the end months have the same length, as in part a. The full day-span, however, needs to handle end months of different lengths. Simply saying that all the long months preceded all the short months, or that the program now works using the three new procedures, earned you no credit. Some of you lost a point or two for a description that wasn't sufficiently detailed; e.g. you had to say something about the program, not just provide an abstract explanation. 5

Problem 5 (5 points) This problem asked you to produce test cases for a given procedure. The versions all involved an is legal? procedure with a single argument, checking for a two-word sentence, one of whose words is an integer in a given range. Here are eleven categories for test arguments: something that s not a sentence; an empty sentence; a one-word sentence; a sentence containing three or more words; a sentence whose symbolic word (the word that s not an integer) is incorrect; a sentence in which what should be an integer isn t an integer; a sentence in which the integer element is too big; a sentence in which the integer element is too small; a sentence in which the integer element is as small as legally allowed; a sentence in which the integer element is as large as legally allowed; a sentence with the words in reverse order (overlaps two of the above cases, but would provide useful debugging information). You received ½ point for each test case (and explanation) that didn t overlap any of your other tests. Fractional totals were rounded up. Some special-case deductions: if your calls used two arguments instead of one, or if you included test cases but not explanations, you could earn at most 3 out of 5. If you did both these things, you could earn at most 2 out of 5. You only received credit for one of a pair of tests for one-word sentences, even if one sentence contained a number and another didn t. Test arguments like (EE (101)) or (#t 101) were treated like any other non-sentence. Commonly overlooked test cases included the following: the empty sentence; an argument that s not a sentence; a number that s not an integer. Many people focused on the number part of the argument and not on the other areas, such as length, data type, etc. 6

Problem 6 (7 points) This problem was the same in all versions. You were to fill in base cases for a precedes? procedure that, given two words (word1 and word2) and a sentence (sent) as arguments, should return true when word1 occurs before word2 in sent. We announced at the exam that precedes? should return #f if the two words are the same, and that you were allowed to assume that the words in the sentence argument are all different. Here s the most common solution. (define (precedes? word1 word2 sent) ((empty? sent) #f) ((equal? (first sent) word1) (member? word2 (bf sent)) ) ((equal? (first sent) word2) #f) The last clause isn't necessary, because the recursion will continue until the sentence is empty if we omit it. The assumption that the words in the sentence are all different combined with the member? call handles the case where the two word arguments are identical. You can replace the call to empty? by checking that sent contains both word1 and word2; this also simplifies the result when we find word1. (define (precedes? word1 word2 sent) ((equal? word1 word2) #f) ((or (not (member? word1 sent)) (not (member? word2 sent)) ) #f) ; includes the case when sent is empty ((equal? (first sent) word1) #t) ; word2 is in sent, so it must follow word1 This was worth 7 points, 2 for checking for an empty sentence (or for both words in sent as just described) and 5 for the rest. Deductions included the following: 1 All (collective) parenthesis errors. 1 Checking for empty words. An empty word is a perfectly reasonable sentence element. 1 Simple substitution errors, e.g. and for or or vice versa, (empty? (bf sent)) instead of (empty? sent). (The latter was particularly common.) 1 Returning something like false or ( ) instead of #f. 1 Returning #t when the word arguments are equal. This often resulted from the cond clause ((equal? (first sent) word1) (member? word2 sent)). 2 No empty check. 2 Works only if word1 and word2 occur consecutively in sent (quite common). 3 After a small correction, works only if word1 and word2 occur consecutively in sent. 7

4 Always returns #t when (equal? (first sent) word1) and word2 in sent hasn't been checked. ( 3 if accompanied by a check for identical word arguments.) 5 Checks neither that (equal? (first sent) word1) nor that (member? word2 sent). ( 4 if accompanied by a check for identical word arguments.) Extra base cases were not penalized (provided they didn t produce incorrect behavior). Another common error was to call first or butfirst without first checking for an empty sentence. 8