CS150 Sample Final. Name: Section: A / B

Similar documents
CS150 Sample Final Solution

CS150 - Sample Final

: Intro Programming for Scientists and Engineers Final Exam

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010

Short Answer Questions (40 points)

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

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

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

COS 126 General Computer Science Fall Written Exam 1

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields.

Midterm Exam 2B Answer key

CSCI 101 Midterm Sample Questions

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

CS 1301 Exam 1 Fall 2014

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

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

CS 1301 Exam 1 Fall 2014

ICS 31 UC IRVINE. ############## YOUR UCINET #### K E Y #### ############## Second Midterm YOUR NAME YOUR STUDENT ID (8 DIGITS)

CS1800 Discrete Structures Final Version A

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

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

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

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

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

CS 2316 Exam 3. Practice. Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

A Function that Calls Itself. It Doesn t Do Anything! Defining a Recursive Function. 2) Base Case. 1) Divide and Conquer 11/22/2010

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

Final Exam in Algorithms and Data Structures 1 (1DL210)

CS 115 Exam 2 (Section 1) Spring 2017 Thu. 03/31/2017

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

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

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

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

CS3 Midterm 2 Summer 2008

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

Q1 Q2 Q3 Q4 Q5 Q6 Total

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher

Notices. Test rules. Page 1 of 8. CS 1112 Spring 2018 Test 2

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

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

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

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

Test #2 October 8, 2015

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

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

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS 111X - Fall Test 1

Control Structures 1 / 17

15-110: Principles of Computing, Spring 2018

CS 2316 Exam 1 Spring 2014

COS 126 General Computer Science Spring Midterm 1

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Structure and Interpretation of Computer Programs

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

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Midterm 1

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

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

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

You must bring your ID to the exam.

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

CS1210 Lecture 28 Mar. 27, 2019

Structure and Interpretation of Computer Programs

CSE 247 Data Structures and Algorithms Fall Exam I

CS16 Exam #1 7/17/ Minutes 100 Points total

15-110: Principles of Computing Sample Exam #1

Multiple-choice (35 pt.)

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours!

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

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

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

Math 1MP3, final exam

CSE 131S Introduction to Computer Science Summer SON Exam I

CS 1301 Exam 2 Fall 2010

CS 115 Exam 2 (Section 1) Fall 2017 Thu. 11/09/2017

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

CS171 Midterm Exam. October 29, Name:

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Problem Solving for Intro to Computer Science

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

CS 1301 Exam 1 Fall 2011

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

CSE 131 Introduction to Computer Science Fall Exam I

CS 115 Exam 3, Spring 2014

Spring 2017 CS 1110/1111 Exam 1

(Refer Slide Time: 01.26)

CS150 - Final Cheat Sheet

Topics: Material through example 19 (types, operators, expressions, functions, selection, loops, arrays)

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

Final Exam. COMP Summer I June 26, points

CS 1301 Post Exam 3 Practice Spring 2016

Practical Questions CSCA48 Week 6

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

Transcription:

CS150 Sample Final Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1) the final cheat sheet from the course page, and (2) a single double-sided sheet of notes. You have 3 hours. Read the problem descriptions carefully and write your answers clearly and legibly in the space provided. Circle or otherwise indicate your answer if it might not be easily identified. You may use extra sheets of paper, stapled to your exam, if you need more room, as long as the problem number is clearly labeled and your name is on the paper. If you attached extra sheets indicate on your main exam paper to look for the extra sheets for that problem. You do not need to include comments, docstrings or constants in your code. 1: Odds and Ends X 2: Vector execution X 3: Dictionaries X 4: Recursion X 5: We ve got problems X 6: Sequences X Total X 1

1. [X points] Odds and Ends (a) [X pts] Indicate whether each of the following statements are True or False. For all possible inputs merge sort has lower asymptotic time complexity than selection sort. 01101 in binary is equal to 13. All columns in a pandas DataFrame must have the same type. If we typed the two first statements below, s would have the value shown below: >>> s = "this is a test" >>> s.upper() THIS IS A TEST >>> s THIS IS A TEST For an O(n 2 ) algorithm, if the algorithm takes 10 seconds to run on 1000 items we would expect it to take approximately 40 seconds on 2000 items. (b) [X pts] Add the following two binary numbers: 01101101 with 00111101 assuming they both are unsigned positive integers. Show your work (including all carries) and verify your answer by converting both numbers and their sum to decimal. 2

(c) [X pts] Given the following code in a file called my file.py: if name == " main ": print("bananas " * 2) print("apples"[:-3]) print("end of " + name ) i. What would be printed if the file were run by clicking on the green arrow? ii. What would be printed if we executed import my_file in the Python shell? (d) [X pts] The xor (exclusive or) of two boolean values is True if either value is True, but is False if they are both True or both False. The following is the truth table for xor: a b xor(a, b) False False False False True True True False True True True False Write a function xor that calculates the exclusive or of two boolean variables. Remember to use good boolean style! 3

2. [X points] Vector execution (a) [X pts] In the following R code, assume a and b are equal-length vectors of numbers. mystery <- function(a, b) { sum(a * b) } i. Rewrite the above code in Python using NumPy and/or pandas as appropriate assuming that a and b are lists of floats. You will be evaluated based on the efficiency and conciseness of your approach. ii. Rewrite the above code in Python using only built-in functions assuming that a and b are lists of floats. You will be evaluated based on the efficiency and conciseness of your approach. (b) [X pts] Which of the above implementations has the smallest Big-O asymptotic time complexity? 4

3. [X points] Dictionaries (a) [X pts] Write a function named dictionary add that takes two dictionaries whose values are numbers and returns a dictionary containing the keys found in both dictionaries. The value associated with these keys should be the sum of the values in the two dictionaries. If a key does not occur in BOTH dictionaries, then it should not occur in the returned dictionary. For example: >>> d1 = {"a": 1, "b": 2, "c": 3} >>> d2 = {"a": 4, "c": 5, "d": 6} >>> dictionary_add(d1, d2) {'a': 5, 'c': 8} (b) [X pts] In one sentence, what does the following function do if dict1 and dict2 are dictionaries? Be concise but precise. def mystery(dict1, dict2): for key in dict1: if not key in dict2: return False return True 5

4. [X points] Recursion (a) [X pts] Draw the image that would be created by the above code if invoked as mystery(80, 5). Assume that the turtle is initially at the origin, facing right. Annotate your drawing with the final turtle location and orientation. from turtle import * def mystery(length, levels): if levels == 0: dot() forward(length) left(90) mystery(length/2, levels-1) right(90) backward(length) 6

(b) [X pts] What does the following function return when invoked with "CS class" as its argument? def mystery(s): if s == "": return s if s[0].isupper(): return s[0].lower() + mystery(s[1:]) return s[0].upper() + mystery(s[1:]) (c) [X pts] Write a recursive function named sum_squared that takes a list of numbers as a parameter and returns the sum of the each of the numbers squared. For example, sum_squared([1, 2, 3]) would return 14 (that is, 1 1 + 2 2 + 3 3 = 14). 7

5. [X points] We ve got problems... (a) [X pts] The following program expects two command-line arguments. The program is supposed to print the usage if the user doesn t supply exactly two arguments, or run the function my_function(...) if the user does supply two arguments. However, the program has a runtime error and logical error. Fix both problems so that it works as expected. You don t have to rewrite the function, just mark-up the one below. import sys def my_function(a, b): # some function stuff def print_usage(): print("my_program.py <number> <number>") number1 = sys.argv[0] number2 = sys.argv[1] if len(sys.argv)!= 2: print_usage() my_function(number1, number2) (b) [X pts] The following function attempts to check if a number is prime or not, but it has a logical error. Correct the function: import math def isprime(num): """Returns True if the input is a prime number, False otherwise""" for i in range(2, int(math.sqrt(num)+1)): if num % i == 0: return False return True 8

6. [X points] Sequences (a) [X pts] Write a function named unique that takes a string as a parameter and returns True if all of the characters in the string are unique (i.e no repeats) or False if there are duplicate letters. You will be evaluated based on the efficiency and conciseness of your approach. (b) [X pts] Write a function name reverse_sentence that takes a string representing a sentence as a parameter and returns a new string where all the words in the sentence are in reverse order. You can assume a word is anything separated by a space. For example: >>> reverse_sentence("this is a sentence") sentence a is this 9