PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS2500 Exam 2 Fall 2011

Software Development Techniques. December Sample Examination Paper. Time: 3 hours

CSE 131 Introduction to Computer Science Fall Exam I

CSC309 Midterm Exam Summer 2007

A Constant Rate of Change Name Part 1

Software Development Techniques. December Sample Exam Marking Scheme

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Annie Lin, Mohit Verma

Midterm spring. CSC228H University of Toronto

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

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

Student Number: Lab day:

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

(ii) Define a function ulh that takes a list xs, and pairs each element with all other elements in xs.

UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

NONE (in particular, no calculator)

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING. FINAL EXAMINATION, December, DURATION: 2 and½ hrs

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

Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100

UNIVERSITY REGULATIONS

CSE 131 Introduction to Computer Science Fall Exam I

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 131 Introduction to Computer Science Fall Exam II

UNIVERSITY OF TORONTO SCARBOROUGH WINTER 2016 EXAMINATIONS. CSC B20H3 Duration 3 hours. No Aids Allowed

CSE 131 Introduction to Computer Science Fall Exam I

CSE332 Summer 2010: Final Exam

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

ii

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

FAMILY NAME: (Print in ink) GIVEN NAME(S): (Print in ink) STUDENT NUMBER: SIGNATURE: (in ink) (I understand that cheating is a serious offense)

UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2015 EXAMINATIONS. CSC309H1 F Programming on the Web Instructor: Ahmed Shah Mashiyat

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

Expression Values Operators. (string-append a b c ) a, b, c string-append. (substring abcd 0 2) abcd, 0, 2 substring

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Outline. Helper Functions and Reuse. Conditionals. Evaluation Rules for cond. Design Recipe with cond. Compound Data

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Name: utorid: U of T

FAMILY NAME: (Print in ink) GIVEN NAME(S): (Print in ink) STUDENT NUMBER: SIGNATURE: (in ink) (I understand that cheating is a serious offense)

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

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

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Midterm Exam 2 CS 455, Spring 2015

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Midterm Examination CLOSED BOOK

CSE331 Winter 2014, Midterm Examination February 12, 2014

Global Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

CIS 110 Introduction to Computer Programming Summer 2014 Final. Name:

Last Name Student Number. Last Name Student Number

YOUR NAME PLEASE: *** SOLUTIONS ***

ESC101 : Fundamental of Computing

GIRLS SECONDARY, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2015/2016

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2016 EXAMINATIONS. CSC309H1 S Programming on the Web Instructor: Ahmed Shah Mashiyat

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

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

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

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

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

OF VICTORIA EXAMINATIONS- DECEMBER 2011 CSC

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

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

UNIVERSITY OF TORONTO Department of Computer Science April 2014 Final Exam CSC373H1S Robert Robere Duration - 3 hours No Aids Allowed.

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

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

CS171 Midterm Exam. October 29, Name:

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

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

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

CS 314 Principles of Programming Languages. Lecture 16

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

14 October 2015 EECS-3421A Test #1 p. 1 of 14. EECS-3421A Test #1. Design

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Midterm Exam 2B Answer key

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSE373 Fall 2013, Midterm Examination October 18, 2013

CSE 131S Introduction to Computer Science Summer SON Exam I

ECE264 Spring 2013 Final Exam, April 30, 2013

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

My dear students, Believe in yourselves. Believe in your abilities. You have got this! -Dr. M

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

Transcription:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2017 EXAMINATIONS CSC 104 H1S Instructor(s): G. Baumgartner Duration 3 hours PLEASE HAND IN No Aids Allowed Student Number: 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. Marking Guide # 1: / 6 This Final Examination paper consists of 9 questions on 18 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 paper is complete and fill in your name and student number above. Answer each question directly on this exam paper, in the space provided. If you need more space for one of your solutions you may also use a blank page at the end of the paper (in which case make sure to mention that where the question is asked). If you leave a Question blank, or a Part of a Question blank, or clearly cross out your answer with a diagonal line, you will receive 25% of the marks allocated to that Question or Part. # 2: / 9 # 3: / 6 # 4: /15 # 5: /13 # 6: / 4 # 7: / 8 # 8: /12 # 9: / 8 TOTAL: /81 Page 1 of 18 Good Luck! over...

CSC 104 H1S Final Reminders The datatypes used in contracts: image number string boolean list function The Intermediate Steps for map, apply, and repeated: ; map : function list -> list (map f (list a b c...)) => (list (f a) (f b) (f c)...) ; map : function list list -> list (map f (list a b c...) (list x y z...)) => (list (f a x) (f b y) (f c z)...) ; apply : function list -> any (apply f (list a b c...)) => (f a b c...) ; repeated : function any number -> list (repeated f a n) => (list a (f a) (f (f a))...) ; with n elements. Page 2 of 18 cont d...

Examination April 2017 Question 1. [6 marks] Part (a) [3 marks] Convert the number 104 into its binary representation, showing your work. Part (b) [3 marks] The number 4203 has the binary representation: 1000001101011. Use that fact to determine the binary representations of: 8406 4202 2101 Include a brief explanation or demonstration of how you used the representation of 4203 to produce the representations of the other three numbers. Page 3 of 18 over...

CSC 104 H1S Final Question 2. [9 marks] Read the following definition of a function T: (define (T n) (cond [(= n 0) (triangle 10 "solid" "black")] [else (above (T (- n 1)) (flip-vertical (beside (T (- n 1)) (T (- n 1)))))])) Part (a) [3 marks] Draw the values of (T 0) and (T 1): Part (b) [2 marks] Complete this design check-expect, using (T 1) [do not draw anything]: (check-expect (T 2) Part (c) [4 marks] Draw the values of (T 2) and (T 3): Page 4 of 18 cont d...

Examination April 2017 Question 3. [6 marks] Read the definition of function T-count, which produces the number of triangles used to produce the result of the function T from Question 2. ; T-count : number -> number (define (T-count n) (cond [(= n 0) 1] [else (+ (T-count (- n 1)) (T-count (- n 1)) (T-count (- n 1)))])) Part (a) [3 marks] Briefly explain why T-count takes a very long time to calculate (T-count 100). Part (b) [3 marks] Suggest a small change in the [else...] clause of the body of T-count, that is still recursive [it must use (T-count (- n 1)) at least once], but produces the same result in much less time. Briefly explain why your change allows (T-count 100) to produce its result quickly. Page 5 of 18 over...

CSC 104 H1S Final Question 4. [15 marks] Part (a) [1 mark] Read the following definition of a function C. Fill in the contract for C.. ; C : -> (define (C n) (circle (* 10 (+ 2 n)) "outline" "black")) Part (b) [2 marks] Show at least one intermediate step, and the final result value, for the following expression: (C -1) Part (c) [3 marks] Read the following definition of a function next. ; next : list-of-two-numbers -> list-of-two-numbers (define (next pair) (list (- (first pair)) (+ (second pair) (first pair) 1))) For each of the following expressions, show at least one intermediate step, and the final result value: (next (list -1 1)) (next (list 1 1)) Page 6 of 18 cont d...

Examination April 2017 Part (d) [5 marks] Show [at least] the intermediate step for repeated [according to the step for repeated listed on the second page of this exam], and the final result value, for the following expression: (repeated next (list -1 1) 5) Part (e) [4 marks] Read the following definition of a function draw. ; draw : list-of-two-numbers -> image (define (draw pair) (beside (C (first pair)) (C (second pair)))) Show [at least] the intermediate step for map [according to the step for map listed on the second page of this exam], and the final result value, for the following expression. You may use your final result value from Part (d) of this question. (map draw (repeated next (list -1 1) 5)) Page 7 of 18 over...

CSC 104 H1S Final Question 5. [13 marks] Read the following check-expects documenting two functions prepend-0 and prepend-1: (check-expect (prepend-0 "101") "0101") ; Puts a zero at the beginning. (check-expect (prepend-0 "001") "0001") ; Puts a zero at the beginning. (check-expect (prepend-1 "101") "1101") ; Puts a one at the beginning. (check-expect (prepend-1 "001") "1001") ; Puts a one at the beginning. Part (a) [4 marks] Define the two functions prepend-0 and prepend-1, including their contracts. Part (b) [4 marks] Consider the following check-expects documenting a function count: (check-expect (count 1) (list "")) (check-expect (count 2) (list "0" "1")) (check-expect (count 4) (list "00" "01" "10" "11")) (check-expect (count 8) (list "000" "001" "010" "011" "100" "101" "110" "111")) Complete the following as a design check-expect by using (count 4), and the functions prepend-0 and prepend-1, to produce the the list for (count 8) documented above. (check-expect (count 8) Page 8 of 18 cont d...

Examination April 2017 Part (c) [5 marks] Define the function count, including its contract. You can assume the input is a power of 2. ; count : -> ; For a number n that is a power of 2 [for example: 1, 2, 4, 8, 16,...], ; produce a list of strings with the binary representations of 0, 1, 2,..., n-1. (define (count n) Question 6. [4 marks] Recall the the built-in function explode that takes a string and produces a list of each character from it. ; explode : string -> list-of-strings (check-expect (explode "It isn t?") (list "I" "t" " " "i" "s" "n" " " "t" "?")) Read this documentation check-expect and contract for a function string-reverse to reverse a string. (check-expect (string-reverse "It isn t?") "?t nsi ti") ; string-reverse : string -> string Use explode to help you complete the definition of the function string-reverse: (define (string-reverse a-string) Page 9 of 18 over...

CSC 104 H1S Final Question 7. Part (a) [8 marks] [4 marks] Complete the definition of function q?. ; q? : string string number -> boolean ; ; Produce #true if the length of string-0 is less than the length of string-1, ; or the length of string-1 is more than n [otherwise produce #false]. (define (q? string-0 string-1 n) Part (b) [4 marks] Write the definition of function p?. ; p? : image image -> boolean ; ; Produce #true if the width and height of the first image are both less than the ; width and height of the second image [otherwise produce #false]. Page 10 of 18 cont d...

Examination April 2017 Question 8. [12 marks] Part (a) [6 marks] Read the following definition of a function R: (define (R LoL) (cond [(list? LoL) (reverse (map R LoL))] [else LoL])) Show the final result value of the following expression: (R 1) For the following expression, show [at least] each intermediate step before and after a map is performed, and show the value of the final result: (R (list 3 4)) For the following expression, show [at least] each intermediate step before and after a map is performed, and show the value of the final result. If a step uses (R (list 3 4)) you do not need to show the steps for (R (list 3 4)) again. (R (list 1 2 (list 3 4))) Page 11 of 18 over...

CSC 104 H1S Final Part (b) [6 marks] Read the following definition of a function F: (define (F LoL) (cond [(list? LoL) (reverse (apply append (map F LoL)))] [else (list LoL)])) Show the final result value of the following expression: (F 1) For the following expression, show [at least] each intermediate step before and after a map or apply is performed, and show the value of the final result: (F (list 3 4)) For the following expression, show [at least] each intermediate step before and after a map or apply is performed, and show the value of the final result. If a step uses (F (list 3 4)), you do not need to show the steps for (F (list 3 4)) again. (F (list 1 2 (list 3 4))) Page 12 of 18 cont d...

Examination April 2017 Question 9. [8 marks] Part (a) [4 marks] Show the result value for each of these expressions: (filter list? (list (list 1 2 3) 4 (list (list 5) 6) 7 8 (list 9 10))) (length (filter list? (list (list 1 2 3) 4 (list (list 5) 6) 7 8 (list 9 10)))) Part (b) [4 marks] Show the intermediate steps and final result value for each of these expressions: (map rest (list (list 1 2 3 4) (list 5 6) (list 7 8 9))) (map + (list 1 2 3) (list 4 5 6)) Page 13 of 18 over...

CSC 104 H1S Final Page 14 of 18 cont d...

Examination April 2017 Use the space on this blank page for scratch work, or for any answer that did not fit elsewhere. Clearly label each such answer with the appropriate question and part number. Page 15 of 18 over...

CSC 104 H1S Final Use the space on this blank page for scratch work, or for any answer that did not fit elsewhere. Clearly label each such answer with the appropriate question and part number. Page 16 of 18 cont d...

Examination April 2017 Use the space on this blank page for scratch work, or for any answer that did not fit elsewhere. Clearly label each such answer with the appropriate question and part number. Page 17 of 18 over...

CSC 104 H1S Final Examination April 2017 Please write nothing on this page. Page 18 of 18 Total Marks = 81 end