: Intro Programming for Scientists and Engineers Final Exam

Similar documents
CS150 Sample Final. Name: Section: A / B

CS 1301 Exam 3 Spring 2014

CS150 Sample Final Solution

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 2 Fall 2010

CS 1301 Exam 3 Fall 2014

CS 2316 Exam 4 Fall 2011

CS 2316 Exam 1 Spring 2014

CS150 - Sample Final

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

CS 1301 Exam 1 Fall 2014

CS 111X - Fall Test 1

CS 2316 Exam 1 Spring 2013

Decisions, Decisions. Testing, testing C H A P T E R 7

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 1 Fall 2014

Midterm #1 Fall minutes

CS 1301 Exam 1 Spring 2011

CS 2316 Exam 4 Fall 2011

CS 1301 Post Exam 3 Practice Spring 2016

CS 1301 Exam 1 Fall 2011

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

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 1 Spring 2014

Last Name: First: Netid: Section. CS 1110 Final, December 17th, 2014

CS 1110 Final, December 17th, Question Points Score Total: 100

CS 1301 Exam 3 Spring 2012

CS 2316 Exam 4 Fall 2014

PREPARING FOR THE FINAL EXAM

CS 2316 Exam 3 Fall 2011

CS 1301 Exam 3 Fall 2010

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

CS 2316 Exam 4 Fall 2012

CS 1110 Final, December 8th, Question Points Score Total: 100

CS 1301 Exam 2 A Fall 2015

TUPLES AND RECURSIVE LISTS 5

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

CS 1301 Exam 2 Fall 2013

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CS 2316 Exam 4 Fall 2012

Math 308 Autumn 2016 MIDTERM /18/2016

Programming with Python

Math 4242 Polynomial Time algorithms, IndependentSet problem

CS 1110 Final, December 8th, Question Points Score Total: 100

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

CS 1301 Exam 2 Fall 2014

CS 2316 Exam 4 Spring 2013

Structure and Interpretation of Computer Programs Spring 2014 Final (with corrections)

EXAM Computer Science 1 Part 1

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Numerical Methods. Centre for Mathematical Sciences Lund University. Spring 2015

ENGR 102 Engineering Lab I - Computation

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Sample Examination Paper Programming and Software Development

COS 126 General Computer Science Fall Exam 1

Spring 2017 CS 1110/1111 Exam 1

If Statements, For Loops, Functions

This exam has 10 pages including the title page. Please check to make sure all pages are included.

CS 1301 Exam 2 Spring 2014

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

CS 1301 Exam 1 Spring 2015

Structure and Interpretation of Computer Programs

CS 1110 Prelim 2 November 6th, 2012

ARTIFICIAL INTELLIGENCE AND PYTHON

CS 1301 Exam 3 A Spring 2015

Spring 2017 CS 1110/1111 Exam 2

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Introduction to Programming with JES

1 Fall 2017 CS 1110/1111 Exam 3

ENGR 102 Engineering Lab I - Computation

CS Name : Grading TA:

CS 1803 Fall 2010 Exam 1

CS 1110 Final, December 9th, Question Points Score Total: 100

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

a b c d a b c d e 5 e 7

CSE wi Midterm Exam 2/8/18. Name UW ID #

Skills Quiz - Python Edition Solutions

CS 2316 Exam 3 Fall 2012

CS 1110 Prelim 1 October 15th, 2015

Functions and Decomposition

SCHEME AND CALCULATOR 5b

MITOCW watch?v=0jljzrnhwoi

CS 101 Spring 2007 Midterm 2 Name: ID:

Spring 2017 CS 1110/1111 Exam 3

Csci 102: Sample Exam

CS 1110 Final, December 16th, 2013

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Spring Semester 09 Exam #2 Dr. Dillon. (04/02)

SYMMETRY v.1 (square)

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

Exam Percentage: / 55 = %

CS 1301 Exam 1 Fall 2013

OCR H446 A-Level Computer Science

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

Version B Final Exam

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

Structure and Interpretation of Computer Programs

Transcription:

Final Exam Page 1 of 6 600.112: Intro Programming for Scientists and Engineers Final Exam Peter H. Fröhlich phf@cs.jhu.edu December 20, 2012 Time: 40 Minutes Start here: Please fill in the following important information using a permanent pen before you do anything else! Your exam will not be graded if you use a pencil or erasable ink on this page. Name (print): Email (print): Ethics Pledge: With your signature you certify the information above and you also affirm the following: I agree to complete this exam without unauthorized assistance from any person, materials, or device. Signature: Date: Instructions: Please read these instructions carefully before you start. Switch off your phones, pagers, and other noisy gadgets! You are not allowed to have anything but a pen (pencil, eraser) and this exam on your desk. You are not allowed to talk to anyone during the exam. If you have a question, please raise your hand quietly. You must remain seated quietly until all exams have been collected. Remember that you can not claim grading errors if you do not use a permanent pen for your answers. Do not open before you are told to do so! You got out of 40 points.

Final Exam Page 2 of 6 1 Binary Warmup (12 points) For each of the following statements, determine whether it is either true or false. (1 point each) 1. import this # :-) 2. According to the PEP8 standard, the proper indentation level for PYTHON code is four spaces. 3. In PYTHON, the keys you put into a dictionary have to be immutable. 4. In PYTHON, calling a function that does not execute a return instruction evaluates to None. 5. The BUBBLE SORT algorithm requires O(n 2 ) time to sort a list of n elements. 6. In PYTHON, variables defined inside a function do not affect variables defined outside the function. 7. In PYTHON, the expression you.can().do.this() must always lead to an error. 8. In PYTHON, tuples cannot be modified after they have been created. 9. Doctests not only help you write correct code, they also provide examples of how to use a function. 10. PYTHON uses dots as in big.small to select a component small out of a composite big. 11. By default PYTHON prints floating point numbers with complete accuracy. 12. In a sorted list of length n we can find a particular element in O(log n) time.

Final Exam Page 3 of 6 2 Tough Choices (8 points) For each of the following questions, circle one answer out of the choices given. (2 points each) 1. You need to draw a three-dimensional plot of a function f : R R R for some math course you re taking. Which PYTHON library do you try first? (a) I ll pick NUMPY because I ll need matrices. (b) I ll pick PYGAME because I can animate the plot. (c) I ll pick MATPLOTLIB because it worked before. (d) All of the above. 2. Which of the following statements is not true about functions in PYTHON? (a) Functions are defined using the keyword def. (b) You can pass functions to other functions as parameters. (c) You can print a function which will print its PYTHON code. (d) Functions can call themselves, directly or indirectly. 3. Assume you have a class Point with a constructor def init (self, x, y): ; which of the following is the correct way to create an instance/object called point of that class? (a) point = Point(10, 20) (b) point = new Point(10, 20) (c) Point(point, 10, 20) (d) point = Point(). init (10, 20) 4. Why, when comparing two floating point numbers a and b for equality, did we not use a == b but instead resorted to abs(a - b) <= 0.001? (a) In PYTHON, floating point numbers do not support the == operator. (b) Floating point computations are only approximate, so we have to allow for small errors. (c) Floating point computations are rather slow, this was one way to make them faster. (d) All of the above.

Final Exam Page 4 of 6 3 Short Answer (8 points) For each of the following questions, answer in one to three sentences, the shorter the better. (2 points each) 1. You are supposed to write a function square(matrix) that returns True if the given matrix has the same number of rows and columns, False otherwise. Give at least four interesting test cases for the square function. (Do not write the function itself!) 2. The simple games and simulations we developed using PYGAME shared the overall structure of the main game loop. Describe the core elements of that loop. Explain! 3. We saw that matrix computations can be done a lot faster in NUMPY than in plain PYTHON. Why is this the case? How do you have to change your thinking as a programmer to take advantage of NUMPY? Explain! 4. You need to read a text file list.txt in which each line contains a number of fields separated by commas. For example the line Claus,Santa,North Pole,Nice should turn into [ Claus, Santa, North Pole, Nice ]. Write the PYTHON code!

Final Exam Page 5 of 6 4 Backtracking Meetings (12 points) You are working on a program that will schedule a set of meetings across a set of rooms in such a way that no room is double-booked. Meetings have a start time (in hours) from 0 to 23 as well as a duration (in hours) from 1 to 4. Your program uses tuples of two integers to represent meetings: (7, 3) is a 3-hour meeting that starts at 7 am whereas (10, 1) is a 1-hour meeting that starts at 10 am. The input to your program (which you will not write completely for this problem!) is a list of rooms as well as a list of meetings. The output of your program is a (valid!) schedule (i.e. list of meetings) for each room. 1. Write a PYTHON function valid(schedule) that given a schedule (which is a list of tuples as described above, one for each meeting) for a single room returns True if there are no conflicts, False otherwise. Note that [(7, 3), (10, 1)] is a valid schedule. Hint: The sorted() function works for lists of tuples! For example (6, 3) < (7, 3) < (7, 4). (8 points) 2. You choose to represent the final schedule for all rooms as a dictionary: The key is the room number, the value is a list of meetings for that room. Describe on a high level how you would use recursive backtracking to produce this dictionary (i.e. find a valid schedule for all rooms). Don t forget to explain how to determine that no valid schedule exists! (4 points)

Final Exam Page 6 of 6 This page is intentionally mostly blank in case you run out of space elsewhere. If you ended up here early, please go over everything again and remain seated quietly! Make sure that the title page is filled out correctly and in permanent pen. Maybe you want to rewrite your answers in permanent pen as well?