Do not turn this page until you have received the signal to start.

Similar documents
Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start.

Do not turn this page until you have received the signal to start.

Student Number: Instructor: Brian Harrington

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Do not turn this page until you have received the signal to start.

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

CSC148 Fall 2017 Ramp Up Session Reference

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell

First Name: Last Name: Q1: /10

Duration: 90 minutes. Page 1 of 14 Q2: /13 Q3: /13 TOTAL: /38. Bonus /1

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

Do not turn this page until you have received the signal to start.

Question 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program:

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

Question 0. Do not turn this page until you have received the signal to start.

Question 0. Do not turn this page until you have received the signal to start.

Short Python function/method descriptions:

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2014 EXAMINATIONS. CSC 108 H1S Instructors: Campbell and Papadopoulou.

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

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F

Strings are actually 'objects' Strings

Short Python function/method descriptions:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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 Faculty of Arts and Science DECEMBER 2017 EXAMINATIONS. CSC 108 H1F Instructor(s): Campbell, Fairgrieve, and Smith

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Prelim 1 October 15th, 2015

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

CS 1110 Prelim 2 November 14th, 2013

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

CS 1110 Prelim 1 October 17th, 2013

CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number:

Student Number: Lab day:

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

CSCA08 Winter 2018 Week 2: Variables & Functions. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

CS 1110 Regular Prelim 1, March 14th, 2017

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

CIS192 Python Programming

CPD for GCSE Computing: Practical Sheet 6 February 14

STRINGS. We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type.

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

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

CS 1110 Final, December 16th, 2013

CS 1110 Final, December 16th, 2013

Question 1. Part (a) Part (b) Part (c) April 2015 Final Examination Solutions CSC 108 H1S. [16 marks] [3 marks]

Data Structures. Dictionaries - stores a series of unsorted key/value pairs that are indexed using the keys and return the value.

'...' "..." escaping \u hhhh hhhh '''...''' """...""" raw string Example: r"abc\txyz\n" in code;

6. Data Types and Dynamic Typing (Cont.)

CSCA20 Worksheet Strings

Question 1. tmp = Stack() # Transfer every item from stk onto tmp. while not stk.is_empty(): tmp.push(stk.pop())

Python Programming: Lecture 2 Data Types

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

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

Advanced Python. Executive Summary, Session 1

CS150 Sample Final. Name: Section: A / B

CS 1110 Prelim 2 November 6th, 2012

Structure and Interpretation of Computer Programs

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Prelim 1 March 7th, 2013

CS 1110 Final Exam, May 2018

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 1, March 2018

CS 1110 Prelim 2 April 26th, 2016

Credit: The lecture slides are created based on previous lecture slides by Dan Zingaro.

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm 1 CSC148H1F L0201 (Liu)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CSCA48 Term Test 1 Seminar

PYTHON MOCK TEST PYTHON MOCK TEST III

Announcements. Project 5 is on the street. Second part is essay questions for CoS teaming requirements.

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

UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Practical Questions CSCA48 Winter 2018 Week 3

UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Final, May 2017

CS 115 Lecture 8. Selection: the if statement. Neil Moore

Module 3: Strings and Input/Output

Babu Madhav Institute of Information Technology, UTU 2015

Algorithm Design and Recursion. Search and Sort Algorithms

Python I. Some material adapted from Upenn cmpe391 slides and other sources

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

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

PREPARING FOR PRELIM 1

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

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

Lecture 6: Recursion RECURSION

Transcription:

CSCA48 Winter 2015 Midterm Exam Duration 100 minutes Aids allowed: none Student Number: Instructors: Anna Bretscher & Brian Harrington Last Name: First Name: UtorID (Markus Login): Please place a checkmark ( ) beside your tutorial session Tutorial Number Date/Time TA Name Check TUT0001 MO 09:00 10:00 PO 101 Eric Wang TUT0002 MO 10:00 11:00 PO 101 Ryan Williams TUT0003 MO 11:00 12:00 IC 326 Nick Dujay TUT0004 MO 12:00 13:00 BV 361 Kenneth Ma TUT0005 MO 13:00 14:00 AA 209 Weining (William) Zhou TUT0006 MO 16:00 17:00 HW 402 Ben Cooper TUT0007 TU 09:00 10:00 MW 160 Kirisanth (Kiwi) Ganeshamoorthy TUT0008 TU 10:00 11:00 MW 160 Rohini Ragunathan TUT0009 TU 11:00 12:00 HW 408 Anastasios Exacoustos TUT0010 TU 12:00 13:00 HW 408 Ekin Ozcelik TUT0012 WE 09:00 10:00 MW 170 Lev Karatun TUT0013 WE 10:00 11:00 IC 326 Chengyu (Tyrone) Xiong TUT0014 WE 12:00 13:00 AA 112 Faisal Usmani Do not turn this page until you have received the signal to start. This exam consists of 4 questions on 14 pages (including this one). When you receive the signal to start, please make sure that your copy is complete. Proper documentation is required for all functions and code blocks. If you use any space for rough work, indicate clearly what you want marked. Please read all questions thoroughly before starting on any work. We have provided you with grids for your answers, this is simply to help you show the indentation of your code and you are not required to adhere to the grids in any specific way. The University of Toronto s Code of Behaviour on Academic Matters applies to all University of Toronto Scarborough students. The Code prohibits all forms of academic dishonesty including, but not limited to, cheating, plagiarism, and the use of unauthorized aids. Students violating the Code may be subject to penalties up to and including suspension or expulsion from the University. # 1: /10 # 2: /10 # 3: /10 # 4: /15 TOTAL: /45 Total Pages = 14 Page 1 cont d...

[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 2 of 14 cont d...

Question 1. [10 marks] In the space below, write the following function: edit distance(s1, s2): 1 The edit distance of two strings s1 and s2 is defined as: The minimum number of single character changes that would be needed to turn s1 into s2. You may assume that s1 and s2 are the same length, and the only character changes available are replacing one character with another. However, you can receive 2 bonus marks if you assume s1 and s2 may be different lengths, and we can also add and delete characters (you must clearly indicate in your comments if you are attempting the bonus mark. For full marks, your solution must be recursive. 1 Gee... this function looks familiar... almost like it came from somewhere that we were told would be good practice for the midterm... Student #: Page 3 of 14 cont d...

[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 4 of 14 cont d...

Question 2. [10 marks] In the space below, write the following function: all perms(s1): Given a string s1, return a list of all permutations of the letters in s1. For example: all perms( abc ), might return something like: [ abc, bac, bca, acb, cab, cba ] You may solve the problem in any way you wish, but for full marks, the solution must be at least partially recursive (i.e., it may use both loops and recursion). You will be assessed on the efficiency and simplicity of your solution. Student #: Page 5 of 14 cont d...

from math import * def f1(a, b, r): ''' (int, int, float) -> list of (int, int) REQ: 0 < r < 1. ''' if a >= b: return [] # return empty list c = floor(a + (b-a)*r) return f1(a, c, r) + f1(c+1, b, r) + [(a, b)] # concatenate 3 lists [Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 6 of 14 cont d...

Question 3. [10 marks] Consider the function f1 on the previous page: Part (a) [5 marks] In the space below, write the output of the following code: print("step 1":, f1(1, 7, 0.5)) print("step 2:", f1(10, 20, 0.2)) Part (b) [5 marks] In the space below, write a function f2 with the same type contract as f1 such that f2(a, b, r) returns the same list that f1(a, b, r) returns except in reverse order. For full marks, your solution must be recursive, and cannot call any other functions besides floor. You are not required to provide external documentation for this function. Student #: Page 7 of 14 cont d...

The CustomerNode Class class CustomerNode: def init (self, ticket_num, cust_name, next): '''(CustomerNode, int, str, CustomerNode) -> None Create a new CustomerNode with ticket number ticket_num, customer name cust_name, and pointing to next. ''' self._ticket_num = ticket_num self._cust_name = cust_name self.next = next def get_ticket_num(self): return self._ticket_num def get_cust_name(self): return self._cust_name The Mangled Code # append any remaining nodes to new_list # append corresponding node to new_list # initialize list to return and its last node # return merged list # test which head of list has smaller ticket_num and # while both lists not empty else: if(l1 == None): if(l1.get_ticket_num() < L2.get_ticket_num()): if(new_list == None): L1 = L1.next L2 = L2.next last = L1 last = L2 last = None last.next = L1 last.next = L2 new_list = L1 new_list = L2 new_list = None return new_list while(l1!= None and L2!= None): Student #: Page 8 of 14 cont d...

Question 4. Part (a) [10 marks] [15 marks] Nick s Deli has just two servers, Anna and Brian. It s a small operation. To control their long queues of customers, they use a roll of numbered tickets. Each successive ticket s number is one greater than its previous ticket s number. On entry every customer takes the next available ticket and lines up either in Anna s queue or in Brian s queue. Sometimes Anna or Brian must leave to teach an A48 lecture. When this happens the two queues are merged into a single queue, and all customers are served in the order they arrived (i.e., ordered by their ticket number). Nick decided to write some code to simulate the queues at his deli. He used linked lists to represent queues. First he created the class CustomerNode for the nodes in his linked list. Then he wrote a function called listmerge(), which takes two sorted (by ticket number) linked lists of customers, and returns a single sorted list of customers from the two original lists. Then disaster happened (guess who...). The CODE MANGLER struck! The docstring was erased. All indentation was removed, and duplicate lines were deleted, then the remaining lines of code (including internal comments) were shuffled. The mangled code can be found on the previous page 2. Please reconstruct Nick s listmerge() function. def listmerge(l1, L2): '''(CustomerNode, CustomerNode) -> CustomerNode Merge the linked lists headed by L1 and L2 into a single list with ticket_num in increasing order. Return the head of the merged list. REQ: Lists headed by L1 and L2 are sorted by ticket_num, all ticket_num values are unique. ''' 2 You are not required to use the mangled code, but it is strongly recommended that you do Student #: Page 9 of 14 cont d...

[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 10 of 14 cont d...

Part (b) [5 marks] Provide a series of test cases (full UnitTest not required, just simple assertions), to test your listmerge function from part a. We ve given you one test case to get you started. Code L1 = None L2 = None r = listmerge(l1, L2) assertequal(r, None) Explanation Merging 2 empty lists, should result in an empty list Student #: Page 11 of 14 cont d...

[Use the space below for rough work. This page will not be marked unless you clearly indicate the part of your work that you want us to mark.] Student #: Page 12 of 14 cont d...

Short Python function/method descriptions: You may tear this page off, but if you do so, you must not include any work on it (front or back) that you wish to have marked. builtins : abs(number) -> number Return the absolute value of the given number. max(a, b, c,...) -> value With two or more arguments, return the largest argument. min(a, b, c,...) -> value With two or more arguments, return the smallest argument. isinstance(object, class-or-type-or-tuple) -> bool Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object's type. int(x) -> int Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero. str(x) -> str Convert an object into a string representation. str: S.count(sub[, start[, end]]) -> int Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation. S.find(sub[,i]) -> int Return the lowest index in S (starting at S[i], if i is given) where the string sub is found or -1 if sub does not occur in S. S.isalpha() --> bool Return True if and only if all characters in S are alphabetic and there is at least one character in S. S.isdigit() --> bool Return True if and only if all characters in S are digits and there is at least one character in S. S.islower() --> bool Return True if and only if all cased characters in S are lowercase and there is at least one cased character in S. S.isupper() --> bool Return True if and only if all cased characters in S are uppercase and there is at least one cased character in S. S.lower() --> str Return a copy of S converted to lowercase. S.replace(old, new) -> str Return a copy of string S with all occurrences of the string old replaced with the string new. S.split([sep]) -> list of str Return a list of the words in S, using string sep as the separator and any whitespace string if sep is not specified. S.startswith(prefix) -> bool Return True if S starts with the specified prefix and False otherwise. S.strip() --> str Return a copy of S with leading and trailing whitespace removed. S.upper() --> str Return a copy of S converted to uppercase. Total Pages = 14 Page 13 cont d...

list: append(...) L.append(object) -- append object to end count(...) L.count(value) -> integer -- return number of occurrences of value index(...) L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. insert(...) L.insert(index, object) -- insert object before index pop(...) L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. remove(...) L.remove(value) -- remove first occurrence of value. Raises ValueError if the value is not present. set: pop(...) Remove and return an arbitrary set element. Raises KeyError if the set is empty. dict: keys(...) D.keys() -> a set-like object containing all of D's keys get(...) D.get(k[,d]) -> returns D[k] if k is in D, otherwise returns d. d defaults to None. object: init (...) x. init (...) initializes x; called automatically when a new object is created str (...) x. str () <==> str(x) Page 14 of 14 End of Examination