Midterm #2a Fall minutes

Similar documents
Midterm #1a Fall minutes

Midterm #2a Spring minutes

Midterm #2a Spring minutes DO NOT WRITE IN THIS AREA

Midterm #2a Fall minutes DO NOT WRITE IN THIS AREA

Midterm #1 Fall minutes

Midterm #1a Spring minutes

Midterm I Practice Problems

Midterm Exam 2B Answer key

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

CS171 Midterm Exam. October 29, Name:

Midterm Exam 2 CS 455, Fall 2014

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

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

15-110: Principles of Computing, Spring 2018

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

CDA 3103 Computer Organization Exam 1 (Sep. 22th, 2014)

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Structure and Interpretation of Computer Programs

PRACTICE MIDTERM EXAM #2

Functional Programming Mid-term exam Tuesday 3/10/2017

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

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Structure and Interpretation of Computer Programs

Midterm 1. CS Intermediate Data Structures and Algorithms. October 23, 2013

Structure and Interpretation of Computer Programs

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

CS 202: Introduction to Computation Fall 2010: Exam #1

Short Answer Questions (40 points)

CS 115 Exam 3, Spring 2015, Sections 1-4

CPSC 217 Midterm (Python 3 version)

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

Exam 2. Name: UVa ID:

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

15-110: Principles of Computing Sample Exam #1

CS Prelim 2 Review Fall 2018

CS1210 Lecture 27 Mar. 25, 2019

CS164: Midterm I. Fall 2003

Midterm Exam 2A Principles of Computing Fall November 10, 2014

CS Homework 10 p. 1. CS Homework 10

COT 3100 Spring 2010 Midterm 2

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Respondus 4.0. Note: Alternatively, click Start, Programs, Respondus, and then select Respondus 4.0 Campus Wide.

CS 115 Exam 3, Fall 2016, Sections 5-8

Programming Languages ML Programming Project Due 9/28/2001, 5:00 p.m.

CS 115 Exam 3, Fall 2015, Sections 1-4

Loop-Body Returns. Another way to terminate a loop.

CMSC330 Spring 2017 Midterm #1 9:30am/11:00am/12:30pm/5:00pm

Structure and Interpretation of Computer Programs

Midterm Exam 2 CS 455, Spring 2015

Midterm 1: CS186, Spring I. Storage: Disk, Files, Buffers [11 points] cs186-

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

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

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS1800 Discrete Structures Final Version A

Examination Questions Midterm 2

Questions Total Points Score

ECE242 Data Structures and Algorithms Fall 2008

Homework /681: Artificial Intelligence (Fall 2017) Out: October 18, 2017 Due: October 29, 2017 at 11:59PM

CSE 123: Computer Networks Fall Quarter, 2013 MIDTERM EXAM

CMSC330 Spring 2017 Midterm #1 Solution

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

CS 115 Exam 3, Spring 2014

: Intro Programming for Scientists and Engineers Final Exam

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

CMSC 330, Fall 2018 Midterm 2

CPSC W2 Midterm #2 Sample Solutions

University of California, Berkeley College of Engineering

MATH 1075 Final Exam

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

Spring 2013 CS 122C & CS 222 Midterm Exam (and Comprehensive Exam, Part I) (Max. Points: 100)

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

Structure and Interpretation of Computer Programs

CSE341, Fall 2011, Midterm Examination October 31, 2011

CIS 3362 Final Exam 12/4/2013. Name:

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:

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

CS 151 Midterm. Instructions: Student ID. (Last Name) (First Name) Signature

n 1 x i = xn 1 x 1. i= (2n 1) = n 2.

Midterm 1 Review Fall 2017 September 8, Functions. Instructions

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.

Spring Semester 13, Dr. Punch. Exam #1 (2/14), form 1 A

Project 1. due date Sunday July 8, 2018, 12:00 noon

15-740/ Computer Architecture, Fall 2011 Midterm Exam II

Asset Keeper Pro - Import Assets

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

Structure and Interpretation of Computer Programs

CSE341, Fall 2011, Midterm Examination October 31, 2011

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

Computer Science Foundation Exam

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

University of Massachusetts Lowell

CS 151 Midterm. (Last Name) (First Name)

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

Transcription:

15-110 Midterm #2a Fall 2018 50 minutes Name: Andrew ID: @andrew.cmu.edu Section: You may not use any books, notes, or electronic devices during this exam. You may not ask questions about the exam except for language clarifications. Show your work on the exam (not scratch paper) to receive credit. If you use scratch paper, you must submit it with your andrew id on it, and we will ignore it. All code samples run without crashing. Assume any imports are already included as required. Do not use these post-midterm2 topics: recursion, etc. DO NOT WRITE IN THIS AREA Part 1 (Very Short Answers) Part 2 (CT) Part 3 (FR / checkkalado) Part 4 (FR / maxdatavalue) Part 5 (FR / coin flips) Part 6/bonus Total 25 points 30 points 15 points 10 points 20 points 5 points bonus 100 points

1. [25 pts; 2.5 pts each] Very Short Answers Answer each of the following very briefly. 1) About how many passes does mergesort require to sort a list of N numbers? 2) About how many total steps (not just passes) does selectionsort require to sort a list of N numbers? 3) What general topic did David Danks discuss in his guest lecture? 4) If M is a list of length 10, this line works just fine: M[3] = 'x' But if M is a string of length 10, that same line will crash. Why? 5) What general topic did Jesse Schell discuss in his guest lecture?

6) In all our Monte Carlo examples, what do we have to do to get a more accurate result? 7) If a function f(l) takes a 1d list L and always returns None, which seems more likely: that f is destructive or non-destructive? 8) What general topic did Lorrie Cranor discuss in her guest lecture? 9) What can you do faster with a set of N unique numbers than with a list of the same N numbers? 10) What can you do with a list of N unique numbers that you cannot do with a set of the same N numbers?

2. [30 pts; 10 pts each] Code Tracing Indicate what each will print. Place your answer in the boxes below each block of code. Show your work, outside the box, for partial credit. def ct1(l): M = [ ] n = len(l) for k in range(n): M.append(L[k][n-1-k]) if (k%2 == 0): M[-1] *= -1 return M print(ct1([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))

def ct2(d): s = set() t = set() for key in d: value = d[key] if (value in s): t.add(value) s.add(value) return sorted(t) print(ct2({1:5, 2:3, 5:3, 4:5, 7:5, 6:4})) def ct3(n): x = 0 y = 0 for i in range(n): try: d = i%10 if (1/d > 0): x += 1 except: y += 1 return [x, y] print(ct3(25))

3. [15 pts] Free Response: checkkalado(l) Here, we will invent the game Kalado, which is a simplified variant of Kaladont. In Kalado, each word has to have at least one letter, and each word (except the first word) has to start with the last character of the previous word, without regard to case (so 'A' and 'a' match). With this in mind, write the function checkkalado(l) that takes a list of words L, and returns True if it is a legal Kalado list, and False otherwise. Notes: * If the list does not have at least 2 words, then it's not a legal Kalado list. * If any word has no characters, then it's not a legal Kalado list. Here are some sample test cases: assert(checkkalado(['ab', 'bc', 'cda', 'ab']) == True) assert(checkkalado(['ab', 'bc', 'ab']) == False) assert(checkkalado(['ab', 'bc']) == True) assert(checkkalado(['ab', '']) == False) assert(checkkalado(['ab']) == False)

4. [10 pts] Free Response: maxdatavalue(path) For this exercise, you may assume the CSV files will contain one header row, followed by rows that only contain comma-separated integers. You may also assume every CSV file contains at least one row and one column of data values. With that in mind, write the function maxdatavalue(path) that takes a path to a CSV file, and returns the largest value that occurs in the data. Hint: you will want to call readcsvfile(path) (which you do not have to write!). Remember: readcsvfile(path) takes a path and returns the data in that csv file as a 2d list.

5. [20 pts] Free Response: coin flips Write these two functions: oddsofallsameflips(n, trials) This function takes two integers, n and trials, both of which you may assume to be positive, and uses Monte Carlo techniques to compute and return the odds that if you flip a coin n times you'll either get n heads or n tails. So oddsofallsameflips(3, 100) would run 100 trials to find the odds that 3 coin flips would result in either 3 heads or 3 tails. trialsucceeds(n) This is a helper function you need to write that runs a single trial using n coin flips. You should call this helper function in oddsofallsameflips (the other function you are writing here). Notes: * You may assume flipcoin() is written for you, and randomly returns 'H' or 'T' * You must use Monte Carlo techniques to receive any credit here, even if you know how to compute the answer directly some other way. [You may use the next page for this question]

[This page intentionally blank] [Exam continues on next page]

6. Bonus/Optional: [5 pts, 2.5 pts each] What will this print? Clearly circle your answer. def bonusct1(n): s = '' for i in range(1,n): try: s += str(float(1/i))[i] except: s += '1' return n+float(s) print(bonusct1(5)) def bonusct2(l): while (len(l)<10): for i in range(l[-2]): L.append(sum(L)%100) return L[-L[0]] print(bonusct2([1,2,3]))