MCS 260 Exam 2 13 November In order to get full credit, you need to show your work.

Similar documents
MATH UN Midterm 2 November 10, 2016 (75 minutes)

CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community

CS103 Handout 22 Fall 2012 November 30, 2012 Problem Set 9

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

Exam 3 MATH Calculus I

Introduction to Python and its unit testing framework

Midterm 1. Name: TA: U.C. Berkeley CS70 : Algorithms Midterm 1 Lecturers: Anant Sahai & Christos Papadimitriou October 15, 2008

Chris Piech CS109 CS109 Final Exam. Fall Quarter Dec 14 th, 2017

Linear equations are equations involving only polynomials of degree one.

University of Regina Department of Mathematics & Statistics Final Examination (April 21, 2009)

Choose three of: Choose three of: Choose three of:

MATH 243E Test #3 Solutions

Math 51 First Exam October 19, 2017

COMPUTER SCIENCE TRIPOS

You have 3 hours to complete the exam. Some questions are harder than others, so don t spend too long on any one question.

COS 341: Discrete Mathematics

Math /Foundations of Algebra/Fall 2017 Foundations of the Foundations: Proofs

Math 42: Fall 2015 Midterm 2 November 3, 2015

Outline. policies for the second part. with answers. MCS 260 Lecture 10.5 Introduction to Computer Science Jan Verschelde, 9 July 2014

Theory of Computation Chapter 12: Cryptography

Parts 3-6 are EXAMPLES for cse634

Shorts

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

Algorithms Exam TIN093 /DIT602

Homework 1 Solutions Probability, Maximum Likelihood Estimation (MLE), Bayes Rule, knn

Problem Point Value Points

MATH 13 SAMPLE FINAL EXAM SOLUTIONS

8. More on Iteration with For

Math 224, Fall 2007 Exam 3 Thursday, December 6, 2007

Socket Programming. Daniel Zappala. CS 360 Internet Programming Brigham Young University

MATH 1553, JANKOWSKI MIDTERM 2, SPRING 2018, LECTURE A

MIDTERM SOLUTIONS: FALL 2012 CS 6375 INSTRUCTOR: VIBHAV GOGATE

MATH 260 LINEAR ALGEBRA EXAM I Fall 2011

Name: Student ID: Instructions:

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

Problem # Max points possible Actual score Total 120

MATH 223 FINAL EXAM APRIL, 2005

MATH 158 FINAL EXAM 20 DECEMBER 2016

MATH 1553, FALL 2018 SAMPLE MIDTERM 2: 3.5 THROUGH 4.4

Agreement Protocols. CS60002: Distributed Systems. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

EE376A - Information Theory Midterm, Tuesday February 10th. Please start answering each question on a new page of the answer booklet.

MATH 1553, C.J. JANKOWSKI MIDTERM 1

CS 170 Algorithms Spring 2009 David Wagner Final

Machine Learning: Homework 5

MATH UN1201, Section 3 (11:40am 12:55pm) - Midterm 1 February 14, 2018 (75 minutes)

Final Exam Math 105: Topics in Mathematics Cryptology, the Science of Secret Writing Rhodes College Tuesday, 30 April :30 11:00 a.m.

Number Theory Math 420 Silverman Exam #1 February 27, 2018

CMSC Discrete Mathematics FINAL EXAM Tuesday, December 5, 2017, 10:30-12:30

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

CHAPTER 2 POLYNOMIALS KEY POINTS

CS534 Machine Learning - Spring Final Exam

Python. chrysn

Turing Machines Part Three

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready.

9A. Iteration with range. Topics: Using for with range Summation Computing Min s Functions and for-loops A Graphics Applications

CS446: Machine Learning Fall Final Exam. December 6 th, 2016

MATH 1553, SPRING 2018 SAMPLE MIDTERM 1: THROUGH SECTION 1.5

VPython Class 2: Functions, Fields, and the dreaded ˆr

2. Polynomials. 19 points. 3/3/3/3/3/4 Clearly indicate your correctly formatted answer: this is what is to be graded. No need to justify!

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt):

Test 2. Monday, November 12, 2018

CSE 546 Final Exam, Autumn 2013

Project 1: ADMI 6807

Name. University of Maryland Department of Physics

MATH 2250 Exam 1 Solutions

Math 440 Project Assignment

Practical Information

1. For each statement, either state that it is True or else Give a Counterexample: (a) If a < b and c < d then a c < b d.

Midterm 2. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

Great Theoretical Ideas in Computer Science

Final Exam December 12, 2017

Solutions to the Midterm Test (March 5, 2011)

Andrew/CS ID: Midterm Solutions, Fall 2006

Selected problems from past exams

2018 Fall 2210Q Section 013 Midterm Exam I Solution

CS103 Handout 08 Spring 2012 April 20, 2012 Problem Set 3

Math 113 Winter 2005 Departmental Final Exam

Introduction to Python

CS177 Fall Midterm 1. Wed 10/07 6:30p - 7:30p. There are 25 multiple choice questions. Each one is worth 4 points.

Read all questions and answers carefully! Do not make any assumptions about the code other than those that are clearly stated.

COMP 204. Exceptions continued. Yue Li based on material from Mathieu Blanchette, Carlos Oliver Gonzalez and Christopher Cameron

Machine Learning, Fall 2009: Midterm

a 2 = ab a 2 b 2 = ab b 2 (a + b)(a b) = b(a b) a + b = b

ECS 189A Final Cryptography Spring 2011

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Unit 4: Quadratic equations in one unknown. Quadratic equations in one unknown

Exam 2 Solutions. x 1 x. x 4 The generating function for the problem is the fourth power of this, (1 x). 4

CSE 555 Homework Three Sample Solutions

Review for Final Exam, MATH , Fall 2010

Exam 3. Math Spring 2015 April 8, 2015 Name: } {{ } (from xkcd) Read all of the following information before starting the exam:

Final. for Math 308, Winter This exam contains 7 questions for a total of 100 points in 15 pages.

MATH 251 Final Examination August 10, 2011 FORM A. Name: Student Number: Section:

Final Exam December 12, 2017

Copy anything you do not already have memorized into your notes.

CMPSCI 105 Final Exam Spring 2016 Professor William T. Verts CMPSCI 105 Final Exam Spring 2016 May 5, 2016 Professor William T. Verts Solution Key

Problem Points Score Total 100

Solution to Midterm Examination

MATH 408N PRACTICE MIDTERM 1

dit-upm RSA Cybersecurity Cryptography

Math 16 - Practice Final

Transcription:

MCS 260 Exam 2 13 November 2015 Name: Do not start until instructed to do so. In order to get full credit, you need to show your work. You have 50 minutes to complete the exam. Good Luck! Problem 1 /15 Problem 2 /10 Problem 3 /21 Problem 4 /21 Problem 5 /25 Problem 6 /8 Total /100

Problem 1 (15 points) Briefly describe what is a network protocol. Secondly, describe what the SMTP protocol is used for. Answer. A network protocol defines a syntax and semantics of messages which are exchanged between computer systems. A network protocol is an agreed upon format for the sequence of bits exchanged between computers, together with a meaning attached to each message. The SMTP protocol is used for email submission. The client sends messages containing data like the recipient, sender, and email content. The server responds with messages informing the client if the email is formatted properly and the email addresses are acceptable. Problem 2 (10 points) Explain the difference between top-down and bottom-up design. Answer. Something like what is on the Day 27 page. Top-down divides a task into subtasks and bottom-up builds components and then links components together to form larger components.

Problem 3 (21 points) Write a python function which takes as an argument the name of a file and returns the number of lines in the file which have length between 10 and 20 characters. That is, 10 len(line) 20. Answer. def foo ( f i l e n a m e ) : with open( filename, r ) as f : cnt = 0 for l i n e in f : i f len ( l i n e ) >= 10 and len ( l i n e ) <= 2 0 : cnt += 1 return cnt Problem 4 (21 points) Write a python class Thermostat which has one property called target temperature and two methods: an initialization method which takes an argument for the initial target temperature and one method turn on heat which takes an argument for the current temperature and returns true if the current temperature is at least 3 degrees below the target temperature and false otherwise. Hint: the solution I wrote consists of 5 lines of code. Yours might be slightly longer but should not be significantly longer. Answer. class Thermostat : def i n i t ( s e l f, temp ) : s e l f. t a r g e t t e m p e r a t u r e = temp def turn on heat ( s e l f, c u r r e n t ) : return c u r r e n t + 3 < s e l f. t a r g e t t e m p e r a t u r e

Problem 5 (25 points) class QuadraticPolynomial : def i n i t ( s e l f, a, b, c ) : #I n i t i a l i z e s a q u a d r a t i c polynomial from the c o e f f i c i e n t s #a, b, and c where the polynomial i s ax ˆ2 + bx + c. #a i s r e q u i r e d to be p o s i t i v e. a s s e r t ( a > 0) s e l f. a = a s e l f. b = b s e l f. c = c def somemethod ( s e l f, x, y ) : i f s e l f. a x 2 + s e l f. b x + s e l f. c <= y : return True else : return False def anothermethod ( s e l f ) : d = s e l f. b 2 4 s e l f. a s e l f. c i f d >= 0 : return [ ( s e l f. b + math. s q r t (d ) ) / ( 2 s e l f. a ), ( s e l f. b math. s q r t (d ) ) / ( 2 s e l f. a ) ] else : return [ ] Explain what somemethod and anothermethod are doing. Then write two python functions (not methods) which take as a parameter a single QuadraticPolynomial and decides if the origin (0,0) is above the polynomial (that is, test if (0,0) is above where the polynomial crosses the y-axis). You should write two different python functions carrying out this same task, one function which uses somemethod and another function which uses anothermethod. You can assume that a > 0 (so that the polynomial opens upward). Hint: the version using somemethod can be done in a single line and the version using anothermethod can be done using four or five lines. Answer. somemethod takes an (x, y) value. It then computes the value of the polynomial at x and compares it with the passed in y value. To test zero above or below it is enough to just pass in (0, 0). def option1 ( poly ) : return poly. somemethod (0, 0)

Answer. anothermethod computes the roots of the polynomial and returns them as a list. If the discriminant is negative there are no roots so the function returns the empty list and otherwise returns the two roots. To test (0, 0), there are three cases. Case 1: there are no roots. Then (0, 0) will be below since a > 0 the poly will open upward. Case 2: zero is between the roots. Then (0, 0) is above since the poly opens upward. Case 3: zero is not between the roots. Then (0, 0) is below since the poly opens upward. def option2 ( poly ) : r = poly. anothermethod ( ) i f len ( r ) > 0 and r [ 1 ] <= 0 and r [ 0 ] >= 0 : # zero between r o o t s return True else : # Zero not between r o o t s or t h e r e are no r o o t s return False

Problem 6 (8 points, 2 points each) Mark whether each statement below is True or False and add one sentence of explanation why it is True or False. You must have a correct explanation to get full credit!!! (a) The python expression [2*x for x in range(5)] produces the list [0, 2, 4, 6, 8, 10]. Answer. False, x ranges through zero through four and is doubled so 10 should not be in the list. (b) After a python object is created, new properties cannot be added to the object. Answer. False, python can add new properties to an object at any time. (c) In python, when calling a function every argument is passed call-by-reference. Answer. False, integers, strings, and floating point are passed call-by-value and objects, lists, and dictionaries are passed call-by-reference. (d) In the k-means clustering algorithm, points are classified by their distance to the nearest centroid. Answer. True, but only for one iteration. As the clustering iterates, points can change their classification by becoming closer to a different cluster center.