Exam 2. Name: UVa ID:

Similar documents
cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

cs1120: Exam 2 Due: Thursday Nov 29 at 3:30pm (in class)

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

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

Introduction to Algorithms

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

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

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

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

Project 5 - The Meta-Circular Evaluator

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

How convincing is our Halting Problem proof? Lecture 36: Modeling Computing. Solutions. DrScheme. What is a model? Modeling Computation

Project 5 - The Meta-Circular Evaluator

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

SCHEME AND CALCULATOR 5b

Structure and Interpretation of Computer Programs

CSE341 Spring 2017, Final Examination June 8, 2017

CSE341 Autumn 2017, Final Examination December 12, 2017

CS 61A Discussion 8: Scheme. March 23, 2017

Structure and Interpretation of Computer Programs

Compilers. Computer Science 431

In addition to the correct answer, you MUST show all your work in order to receive full credit.

CSE341 Spring 2016, Final Examination June 6, 2016

CS164: Midterm I. Fall 2003

Documentation for LISP in BASIC

Structure and Interpretation of Computer Programs

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

YOUR NAME PLEASE: *** SOLUTIONS ***

Structure and Interpretation of Computer Programs

Important Project Dates

CS 314 Principles of Programming Languages. Lecture 16

COMP 401 COURSE OVERVIEW

CS2 Practical 6 CS2Bh 24 January 2005

UNIVERSITY OF CALIFORNIA

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

CS162 Week 1. Kyle Dewey. Friday, January 10, 14

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009


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

CS 1101 Exam 3 A-Term 2013

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

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

CSE341 Spring 2017, Final Examination June 8, 2017

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

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

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

EXAMINATION INSTRUCTIONS

CS 314 Principles of Programming Languages

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

When does RDBMS representation make sense When do other representations make sense. Prerequisites: CS 450/550 Database Concepts

Richard Feynman, Lectures on Computation

CS 241 Data Organization. August 21, 2018

TAIL RECURSION, SCOPE, AND PROJECT 4 11

Midterm I - Solution CS164, Spring 2014

CS 415 Midterm Exam Spring 2002

61A Lecture 3. Friday, September 5

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

cs173: Programming Languages Midterm Exam

cs173: Programming Languages

COSC 115: Introduction to Web Authoring Fall 2013

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

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

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

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

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

Welcome to CS 115 (Winter 2019)

ECE Object-Oriented Programming using C++ and Java

Do not write in this area. Style (10) TOTAL. Maximum possible points: 30

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

CS216: Problem Set 1: Sequence Alignment

Context-Free Grammars

CS 3030 Scripting Languages Syllabus


CSC-461 Exam #2 April 16, 2014

COSC 115A: Introduction to Web Authoring Fall 2014

CSC D84 Assignment 2 Game Trees and Mini-Max

CS100J February 13, 2001

CSC 111 Introduction to Computer Science (Section C)

University of Virginia Department of Computer Science. CS 4501: Information Retrieval Fall 2015

CS100J February 13, 2001

by the evening of Tuesday, Feb 6

: Intro Programming for Scientists and Engineers Final Exam

CS264: Homework #1. Due by midnight on Thursday, January 19, 2017

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

UVa ID: NAME (print): CS 4501 LDI Midterm 1

CS 3360 Design and Implementation of Programming Languages. Exam 1

cs173: Programming Languages Final Exam

Faced with the choice between changing one s mind and proving that there is no need to do so, almost everyone gets busy on the proof.

CS 373: Combinatorial Algorithms, Fall Name: Net ID: Alias: U 3 / 4 1

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 1 Fall 2010

Math 355: Linear Algebra: Midterm 1 Colin Carroll June 25, 2011

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CSE 123: Computer Networks Fall Quarter, 2017 MIDTERM EXAM

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

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS 111X - Fall Test 1

CS157a Fall 2018 Sec3 Home Page/Syllabus

Transcription:

University of Virginia Out: 28 November 2011 cs1120: Introduction of Computing Due: 11:01 am, Wednesday, 30 November Explorations in Language, Logic, and Machines Exam 2 Name: UVa Email ID: Directions Due: 11:01am, Wednesday, 30 November 2011. No late exams will be accepted without prior arrangement or an extraordinarily good story. Since you have 10 days for this exam, the threshold for a good story is significantly higher than it was for Exam 1. Work alone. Between receiving this exam and turning it in on 30 November, you may not discuss these problems or anything directly related to this exam with anyone other than the course staff. You may (and probably should), however, continue to work on Problem Set 8, but must avoid discussing anything directly related to this exam with your PS8 teammates. Open resources. You may use any books you want, lecture notes, slides, your notes, and problem sets, including any materials posted on or linked from the course website. Unlike Exam 1, on this exam you may also use any computer programs you want, including DrRacket, Python, and code from the problem sets including PS7. You may also use external non-human sources including books and web sites. If you use anything other than the course book, slides, notes, and standard interpreters, you must cite what you used clearly in your answer. You may not obtain any help from other humans other than the course staff (who will only answer clarification questions). Answer well. Answer all of the graded questions and the optional, ungraded questions on the last page. A full credit answer for each question is worth 10 points (but it is possible to get more than 10 points for especially elegant and insightful answers). Your answers must be clear enough for us to read and understand. If you do not use our provided print-out, your print-out should use only the front sides of pages and should be printed well enough to be easily read. You should not need more space than is provided to write good answers, but if you need more you may use the backs or attach extra sheets. If you do, make sure the answers are clearly marked. The questions are not necessarily in order of increasing difficulty. There is no time limit on this exam, but it should not take a well-prepared student more than two hours to complete. It may take you longer, though, so please do not delay starting the exam. You should definitely not allow this exam to interfere with your Thanksgiving holiday. Full credit depends on the clarity and elegance of your answer, not just correctness. Your answers should be as short and simple as possible, but not simpler. Your answers will be judged for correctness, clarity and elegance, but you will not lose points for trivial errors (such as missing a closing parenthesis). Pledge: Sign here to indicate that you read, agreed to, and followed all of the directions here in addition to the Course Pledge.

First Question 1. According to Dean Kamen s speech at the Rice Hall dedication (quoting Walt Havenstein), what is the only sport I know where everyone can turn pro? (Note: if you had the misfortune of not being able to attend Dean s talk, you should still be able to answer this question by searching for the quote using DuckDuckGo, Google, or Bing.)

Running Time Analysis 2. Describe the worst-case asymptotic running time of the all-positive? Scheme procedure defined below (from the Exam 1 comments). You may assume that all elements of p have values below some bound k, so the running time of > is constant. Remember to clearly define all variables you use in your answer. (define (all-positive? p) (if (null? p) true ; reached end without finding non-positive, so result is true (if (> (car lst) 0) (all-positive? (cdr lst)) ; keep looking false))) ; found one non-positive 3. Describe the worst-case asymptotic running time of the allpositive Python procedure defined below (that behaves similarly to the Scheme procedure above). You may assume that all elements of p have values below some bound k, so the running time of <= is constant. Remember to clearly define all variables you use in your answer. def allpositive(p): for x in p: if x <= 0: return False return True

4. Describe the worst-case asymptotic running time of the goldstarssquare(g) Python procedure defined below. The input, g, is a natural number. You should state clearly all assumptions you make. Remember to clearly define all variables you use in your answer. The best answers will be in terms of the size of the input, not the value of g, but you will receive nearly full credit for a correct answer in terms of the value of g. def rowgoldstars(g): for i in range(0, g): print "*", print # (end the row by printing a new line) def goldstarssquare(g): for i in range(0, g): rowgoldstars(g)

Mutation 5. Define a procedure that takes as input a mutable list of numbers, and modifies the list so that each element is replaced with its negation. You may use either Scheme or Python to define your procedure (your choice). For example, in Scheme you would define the mlist-negate! procedure that behaves like this: > (define p (mlist 1-2 3 0-17)) > (mlist-negate! p) > p {-1 2-3 0 17} In Python you would define the listnegate procedure that behaves like this: >>> p = [1, -2, 3, 0, -17]] >>> listnegate(p) >>> p [-1, 2, -3, 0, 17]

6. Define a Scheme procedure make-cumulative! that takes as input a mutable list, and modifies the list so that each element is the cumulative total of all elements up to and including itself. For example, > (define p (mlist 1 2 3 4 5)) > (make-cumulative! p) > p {1 3 6 10 15} Hint: you probably should start by defining a helper procedure. (For full credit for this question, you must use Scheme. But, a correct answer using Python is worth most of the credit.) Bonus: what is the asymptotic running time of your make-cumulative! procedure. You should not assume the running time of the + procedure is constant; instead, assume that its running time is linear in the size (number of bits) of its inputs. (Use the back of this page to answer the bonus question, but circle Bonus to indicate that you have something we should look at for this.)

Interpreters Suppose we want to add a new special form to Charme similar to the and special form in Scheme. The grammar for the and special form is: Expression AndExpression AndExpression (and ExpressionList) ExpressionList ε ExpressionList Expression ExpressionList The evaluation rule is: To evaluate the and expression, (and E 0 E 1 E n ), evaluate each sub-expression in order until one evaluates to a false value. If any sub-expression evaluates to a false value, the value of the and expression is false, and none of the following subexpression is evaluated. If none of the sub-expressions evaluate to a false value, the value of the and expression is true. (Note that this means (and) should evaluate to true.) 7. Explain why and needs to be a special form (that is, it requires modifying the Charme evaluator and could not be implemented as a primitive procedure).

8. Define an evaland(expr) procedure that implements the evaluation rule for the and special form. You may assume the value passed in as expr is parsed Charme expression and that corresponds to a syntactically valid and expression.

Computability The cs1120 staff is getting tired of having to grade so many programming questions 1, so wants to build a procedure that automates grading by checking if a solution submitted implements the same function as our reference solution. 9. Is the CORRECT-ANSWER problem defined below computable? For full credit, your answer must include a convincing proof supporting your answer. Input: Strings that define two Python procedures, r (the reference procedure) and s (the submitted procedure). Output: True if the procedure defined by s correctly implements the same function as the procedure defined by r. We say s correctly implements the same function as r if for every input for which r produces a value, s produces the same value. 1 The obvious solution of just asking fewer questions had not occurred to us until we read your PS7 responses, but not everyone finds this solution satisfying.

10. Is the PROBABLY-CORRECT-ANSWER problem defined below computable? For full credit, your answer must include a convincing proof supporting your answer. Input: Strings that define two Python procedures, r (the reference procedure) and s (the submitted procedure), a set V of test inputs, and a number t for the maximum number of steps. Output: True if the procedure defined by s probably implements the same function as the procedure defined by r. We say s probably implements the same function as r if for each element v of V, if r(v) produces a value within t steps, s(v) produces the same value within t or fewer steps.

Problem Score Notes 1 2 3 4 5 6 7 8 9 10 Total