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

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

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

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

First Name: Last Name: Q1: /10

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

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

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

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

Name: utorid: U of T

UNIVERSITY OF TORONTO Faculty of Arts and Science

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

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

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

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

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

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

Student Number: Lab day:

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

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

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

Midterm #1 Fall minutes

Practical Questions CSCA48 Winter 2018 Week 11

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

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Student Number: Instructor: Brian Harrington

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

Practical Questions CSCA48 Winter 2018 Week 3

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

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam.

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

Last name... First name... Q1: / 5 Q2: / 6 Q3: / 9

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

Midterm #1a Fall minutes

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:

Practice midterm exam

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

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

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSCA48 Term Test 1 Seminar

Structure and Interpretation of Computer Programs

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Final Exam Version A

Linked List Practice Questions

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

CSE 131 Introduction to Computer Science Fall Exam II

CSCI 150 Exam 2 Solutions

Csci 102: Sample Exam

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Introduction to Computer Science II (CSI 1101)

Structure and Interpretation of Computer Programs

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

CMPSCI 119 LAB #2 Greebles / Anime Eyes Professor William T. Verts

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

About the Final. Saturday, 7-10pm in Science Center 101. Closed book, closed notes. Not on the final: graphics, file I/O, vim, unix

Midterm #1a Spring minutes

COMPSCI 105 S Principles of Computer Science. 17 Linked List(1)

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

No Aids Allowed. Do not turn this page until you have received the signal to start. Read this entire page or you ll miss the bonus question.

NONE (in particular, no calculator)

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

Turtle Graphics and L-systems Informatics 1 Functional Programming: Tutorial 7

CS 1110 Prelim 2 Solutions April 2018

CS Prelim 2 Review Fall 2018

Representing 2D Transformations as Matrices

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Csci 102: Sample Exam

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

a) Write the signed (two s complement) binary number in decimal: b) Write the unsigned binary number in hexadecimal:

CSE 131 Introduction to Computer Science Fall Exam I

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

Structure and Interpretation of Computer Programs

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

UNIVERSITY OF TORONTO Faculty of Arts and Science

Written test, 25 problems / 90 minutes

Comp 182 Data Structures Sample Midterm Examination

Objects. say something to express one's disapproval of or disagreement with something.

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

UNIVERSITY REGULATIONS

Comp 150 Exam 2 Overview.

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

CS 4620 Midterm, March 21, 2017

Good Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton

CSCE 110: Programming I

Spring 2017 CS 1110/1111 Exam 1

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

Welcome to CSC148! Introduction to Computer Science

Linked Structures Chapter John Wiley & Sons, Data Structures and Algorithms Using Python, by Rance D. Necaise.

Transcription:

CSC A48 Winter 2014 CSCA48 Midterm Test 15 February 2014 Duration: Aids Allowed: 70 minutes None Student Number: UTORid: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. Please put an x beside your tutorial section TUT0001 Philip (Jianho) Yang MO 13-15 TUT0002 Eric Ren MO 15-17 TUT0005 Nick (Ruo Fan) Li TU 10-12 TUT0006 Faisal Usmani WE 12-14 TUT0007 Lev Karatun WE 13-15 TUT0008 Yang Song WE 14-16 TUT0009 Nick Olson-Harris WE 15-17 TUT0010 Yamn Chalich TU 11-13 TUT0011 Harmen Kahlon MO 10-12 TUT0012 Kenneth Ma TU 16-18 TUT0013 Denning Campbell TH 15-17 TUT0014 Judy Duong FR 11-13 This term test consists of 3 questions on 12 pages (including this one), printed on both sides of the paper. When you receive the signal to start, please make sure that your copy of the test is complete, fill in the identification section above, and write your name on the back of the last page. Answer each question directly on the test paper, in the space provided, and use one of the blank pages for rough work. If you need more space for one of your solutions, use a blank page and indicate clearly the part of your work that should be marked. Marking Guide # 1: /10 # 2: /10 # 3: /10 TOTAL: /30 Good Luck! Page 1 of 12

CSC A48 Winter 2014 Use the space on this blank page for scratch work, or for any solution that did not fit elsewhere. Clearly label each such solution with the appropriate question and part number. Page 2 of 12

CSCA48 Midterm Test 15 February 2014 Question 1. [10 marks] class B: def init (self: B, name: str) -> None: self._name = name Write the output of the code in the box below. If a line of code would cause Python to crash, write CRASH, and then continue tracing as though that line had been commented out of the main block. def str (self: B ) -> str: return ("I m a B named " + self._name) def mb(self: B, n: int) -> None: print("mb", self._name, str(n)) class C(B): def init (self: C, name: str) -> None: B. init (self, name) self._name_len = len(name) def str (self: C ) -> str: return ("I m a C named " + self._name + "-" + str(self._name_len)) def mc(self: C, n: int) -> None: print("mc", end = " ") B.mB(self, n+1) class D(C): def init (self: D, name: str) -> None: C. init (self, "Super " + name) self._junk = self._name_len + 3 def mc(self: D, n: int) -> None: print(str(self._junk), end = " ") C.mC(self, n+1) if name == " main ": b = B("Bob") c = C("Carole") d = D("Dan") print("1:", b) print("2:", c) print("3:"d) print("4:") b.mb(12) print("5:") c.mb(13) print("6:") d.mb(14) print("7:") b.mc(15) print("8:") c.mc(16) print("9:") d.mc(17) Page 3 of 12

CSC A48 Winter 2014 Use the space on this blank page for scratch work, or for any solution that did not fit elsewhere. Clearly label each such solution with the appropriate question and part number. Page 4 of 12

CSCA48 Midterm Test 15 February 2014 Question 2. [10 marks] Suppose the function call draw_rectangle(x1, y1, x2, y2) draws a rectangle on an x-y plane with vertices (x1,y1), (x2,y1), (x2,y2), (x1,y2). i.e., it draws a rectangle which sits flat on the line y=y1, with its bottom left corner at (x1,y1), and its top right corner at (x2,y2). Now consider the following recursive function. def funky_rect(x1: int, y1: int, x2: int, y2: int, level: int) -> None: if level <= 0: return xmid = (x1 + x2) // 2 ymid = (y1 + y2) // 2 draw_rectangle(x1, y1, x2, y2) funky_rect(xmid + 5, y1 + 5, x2-5, ymid - 5, level - 1) funky_rect(x1 + 5, ymid + 5, xmid - 5, y2-5, level - 1) a) On the x-y plane below, draw what following function call would draw. funky_rect(-100, -100, 100, 100, 3) + 100-100 100 -+---------------------------------+---------------------------------+- + -100 Page 5 of 12

CSC A48 Winter 2014 Use the space on this blank page for scratch work, or for any solution that did not fit elsewhere. Clearly label each such solution with the appropriate question and part number. Page 6 of 12

CSCA48 Midterm Test 15 February 2014 b) On your diagram above clearly indicate which rectangle that was drawn first, and which was drawn last. c) Rewrite funky_rect in the space below so that the call funky_rect(-100, -100, 100, 100, 3) will still produce the same diagram, except the rectangle that was drawn first will now be drawn last, and the rectangle that was drawn last will now be drawn first. Page 7 of 12

CSC A48 Winter 2014 Use the space on this blank page for scratch work, or for any solution that did not fit elsewhere. Clearly label each such solution with the appropriate question and part number. Page 8 of 12

CSCA48 Midterm Test 15 February 2014 Question 3. [10 marks] Consider the following class for a node used in a (singly) linked list of items, each with a non-negative integer called importance. We let users of ImportanceNode muck around as much as they want with the data stored in a node. class ImportanceNode: def init (self: ImportanceNode, importance: int, data: object) -> None: Create a new ImportanceNode with importance importance. REQ: importance >= 0. self._importance = importance self.next = None self.data = data def get_importance(self: ImportanceNode ) -> int: return self._importance At times we want to move the item with the highest importance to the front of the list. If there are multiple items with highest importance, then the last one of these in the list is moved. Some time ago, Nick started writing the following function to perform the node movement as described above. However, he never finished, nor did he write any internal comments. Here s what he wrote. def move_high(il_head: ImportanceNode ) -> ImportanceNode : From the linked list whose head is il_head, move the node with highest importance to the front. If there are multiple nodes with highest importance, then the last such node in the list is moved. The list is unchanged if it is empty. Return the (head of) updated list. prev = None curr = il_head high = -1 while curr!= None: curr_imp = curr.get_importance() if curr_imp > high: high = curr_imp high_node = curr high_prev = prev curr = curr.next prev = curr if high_prev == None: return il_head high_node.next = il_head return high_node Page 9 of 12

CSC A48 Winter 2014 Use the space on this blank page for scratch work, or for any solution that did not fit elsewhere. Clearly label each such solution with the appropriate question and part number. Page 10 of 12

CSCA48 Midterm Test 15 February 2014 There are 4 bugs in Nick s code. For each bug, describe the bug, and a small change (at most one line) that could be made to fix the bug. To help you get started, we provided the answer for one of the bugs. Bug #0: On a list with multiple nodes of equal highest importance, high_node (node to move) is incorrectly identified. Fix: Change the if condition in loop to if curr_imp >= high: Page 11 of 12

CSC A48 Winter 2014 CSCA48 Midterm Test 15 February 2014 On this page, please write nothing except your name. Last (Family) Name(s): First (Given) Name(s): Total Marks = 30 Page 12 of 12