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

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

Practice midterm exam

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

CSE 160 Winter 2017: Final Exam

CSE 160 Winter 2017: Final Exam

WHOLE NUMBER AND DECIMAL OPERATIONS

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Midterm Exam 2B Answer key

CSE 160 Winter 2016: Final Exam

CSI33 Data Structures

CSE 160 Winter 2016: Final Exam

CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009

Integers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not.

A. Incorrect! To simplify this expression you need to find the product of 7 and 4, not the sum.

CS150 - Sample Final

Structure and Interpretation of Computer Programs

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

CSE 140 Winter 2014: Midterm Exam

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Exponent Properties: The Product Rule. 2. Exponential expressions multiplied with each other that have the same base.

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

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Programming Paradigms Written Exam (6 CPs)

Rational number operations can often be simplified by converting mixed numbers to improper fractions Add EXAMPLE:

Computer Science Foundation Exam

15213 Recitation 2: Floating Point

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 160 Spring 2018: Final Exam

ECE 2400 Computer Systems Programming Fall 2018 Topic 2: C Recursion

Computer Science Foundation Exam

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Watkins Mill High School. Algebra 2. Math Challenge

CSE413 Midterm. Question Max Points Total 100

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Lists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 Solutions. 1 Sequences. Questions. lst = [1, 2, 3, 4, 5] lst[1:3]

CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2015

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

CSE wi: Practice Midterm

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

Unit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

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

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter Lab 8 - Structures

NAME: 1a. (10 pts.) Describe the characteristics of numbers for which this floating-point data type is well-suited. Give an example.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Hints for Exercise 4: Recursion

Working with Rational Expressions

15-110: Principles of Computing, Spring Problem Set 3 (PS3) Due: Friday, February 9 by 2:30PM on Gradescope

Structure and Interpretation of Computer Programs

Algebra II Chapter 8 Part 2: Rational Functions

CSU211 Exam 2 Fall 2007

Unit 3: Rational Numbers ANSWER KEY

What is an algorithm?

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm

Due Date: Friday, September 9 th Attached is your summer review packet for the Algebra 1 course.

CSE 332 Winter 2015: Final Exam (closed book, closed notes, no calculators)

REVIEW OF 6 TH GRADE

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 331 Final Exam 3/16/15 Sample Solution

Randomized Algorithms: Selection

CS1 Lecture 22 Mar. 6, 2019

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

CSE 160 Spring 2015: Midterm Exam

Section 2.3 Rational Numbers. A rational number is a number that may be written in the form a b. for any integer a and any nonzero integer b.

Structure and Interpretation of Computer Programs

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Computer Science E-22 Practice Final Exam

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

UMBC CMSC 331 Final Exam

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

EXAMINATION INSTRUCTIONS

FORM 2 (Please put your name and form # on the scantron!!!!)

CSE 333 Midterm Exam 2/14/14

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

CSE351 Winter 2016, Final Examination March 16, 2016

CS Lecture 18: Card Tricks. Announcements. Slides by D. Gries, L. Lee, S. Marschner, W. White

CSE 131 Introduction to Computer Science Fall Final Exam

RATIONAL FUNCTIONS Introductory Material from Earl Please read this!

MAT 003 Brian Killough s Instructor Notes Saint Leo University

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

PROBLEM SOLVING 11. July 24, 2012

Lesson 1: Arithmetic Review

Name ( ) Person Number ( )

Inf2C - Computer Systems Lecture 2 Data Representation

Structure and Interpretation of Computer Programs

CS 455 Final Exam Fall 2013 [Bono] December 12, 2013

CSE332 Summer 2010: Final Exam

CSE 2123 Recursion. Jeremy Morris

SUMMER REVIEW PACKET 2 FOR STUDENTS ENTERING ALGEBRA 1

Problem Score Maximum MC 34 (25/17) = 50 Total 100

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm Solution

Transcription:

University of Washington CSE 140 Data Programming Winter 2013 Final exam March 11, 2013 Name: Section: UW Net ID (username): This exam is closed book, closed notes. You have 50 minutes to complete it. It contains 8 questions and 7 pages (including this one), totaling 100 points. Before you start, please check your copy to make sure it is complete. Turn in all pages, together, when you are finished. Write your initials on the top of ALL pages (in case a page gets separated during test-taking or grading). Please write neatly; we cannot give credit for what we cannot read. Good luck! Page Max Score 2 20 3 12 4 24 5 12 6 16 7 16 Total 100

Initials: 1 SHORT ANSWER 1 Short answer 1. (6 points) State the steps you should follow when writing a function. Write just one phrase for each step. (These steps come after you have defined the problem and decomposed it into parts, and before you run tests.) Depending on how you break up the tasks, you might write 3, 4, or 5 steps; you can get full credit for any of these answers as long as your steps include all the necessary parts and no extraneous parts. (a) (b) (c) (d) (e) 2. (6 points) Name the two types of documentation, and state for whom each one is intended. (a) Intended for: (b) Intended for: 3. (8 points) State three advantages of splitting up your code into functions. Give reasons that are as different as possible. Write no more than one sentence each (a phrase each is enough). (a) (b) (c) 2

Initials: 2 ENVIRONMENT DIAGRAM 2 Environment diagram 4. (12 points) Consider the following code: def exp(base, exponent): """Return base to the exponent power. Exponent is a non-negative integer.""" if exponent == 0: return 1 if exponent % 2 == 0: return exp(base*base, exponent/2) return base * exp(base, exponent - 1) Here are the powers of 5, for your information: 5 0 = 1 5 1 = 5 5 2 = 25 5 3 = 125 5 4 = 625 5 5 = 3125 5 6 = 15625 Given the expression exp(5, 6), show the stack frames when the multiplication on the last line of code (the multiplication with the box around it) is about to be executed for the first time. What are the two arguments to the multiplication referenced in the last question? 3

Initials: 3 TESTING 3 Testing 5. (24 points) Consider the following function specification: def indices_of(lst, elt): """Return a sorted list of the indices at which the element appears in lst.""" Here is an example test: assert indices_of([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3], 9) == [5, 12, 14] A good test suite contains tests that are different from one another. Apply the 0 1 many principle to the indices of function. Write three different tests, and state what is varying between them. What is varying: Test 1: Test 2: Test 3: Now, use the 0 1 many principle again, but apply it to something different. Again, write three different tests, and state what is varying between them. What is varying: Test 1: Test 2: Test 3: Write an implementation of indices of, in a single line of code. Hint: use a list comprehension. 4

Initials: 4 WRITE CODE 4 Write code 6. (12 points) Write the body of the following function. def word_frequency(list_of_tuples): """Return a dictionary mapping words to numbers. The input is a list of (word, number) tuples. In the output dictionary, each word maps to the sum of all numbers it co-occurs with in the input list.""" Here is a test case, to help you understand the specification: assert word_frequency([("to", 2), ("be", 2), ("or", 2), ("not", 3), ("to", 2), ("be", 2)]) == { be : 4, not : 3, or : 2, to : 4} 5

Initials: 4 WRITE CODE 7. (16 points) Write a class RatNum that represents rational numbers. A rational number is the ratio of two integers; examples are 1 2 and 22 7. You do not have to write any documentation strings. Once your class is defined, then running the following code: one_half = RatNum(1,2) one_third = RatNum(1,3) five_sixths = one_half.add(one_third) print one_half.to_float() print one_third.to_float() print five_sixths.to_float() should print 0.5 0.333333333333 0.833333333333 Hint: Do not define any more methods than necessary. Hint: Recall from middle school that a b + c d = ad+bc bd. Hint: You do not have to deal with client errors, such as using zero as the denominator. Hint: Do not think about reducing fractions to lowest terms. That is not necessary for this problem. (If you don t understand this hint, then don t worry about it.) 6

Initials: 4 WRITE CODE 8. (16 points) Write the body of the following function. Write the function twice: iteratively (using a loop) and recursively (using a recursive call). You may solve the two parts of this problem in either order. You may use the function max(x, y) that takes two numbers and returns the larger one. ## Iterative version def list_max(numbers): """Returns the largest value that appears in the argument list. The argument is a non-empty list of numbers.""" ## Recursive version def list_max(numbers): """Returns the largest value that appears in the argument list. The argument is a non-empty list of numbers.""" 7