The University of British Columbia

Similar documents
UNIVERSITY REGULATIONS

UNIVERSITY REGULATIONS

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

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

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

CS1800 Discrete Structures Spring 2017 Profs. Gold & Schnyder April 28, CS1800 Discrete Structures Final

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

CSE 373 Spring Midterm. Friday April 21st

CSL 201 Data Structures Mid-Semester Exam minutes

This examination has 11 pages. Check that you have a complete paper.

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

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

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Data Structures Question Bank Multiple Choice

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

Name: UTLN: CS login: Comp 15 Data Structures Midterm 2018 Summer

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science E-22 Practice Final Exam

Computer Science Spring 2005 Final Examination, May 12, 2005

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

Dynamic Data Structures

ECE250: Algorithms and Data Structures Midterm Review

Overview of Data. 1. Array 2. Linked List 3. Stack 4. Queue

CSCE 2014 Final Exam Spring Version A

CSE 247 Data Structures and Algorithms Fall Exam I

COS 226 Algorithms and Data Structures Fall Midterm

CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis. Aaron Bauer Winter 2014

Section 1: True / False (2 points each, 30 pts total)

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1

OF VICTORIA EXAMINATIONS- DECEMBER 2011 CSC

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

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

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

Basic Data Structures (Version 7) Name:

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 1

Practice Midterm Exam Solutions

Computer Science Foundation Exam

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

Exam I Principles of Imperative Computation, Summer 2011 William Lovas. May 27, 2011

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

Computer Science 136. Midterm Examination

ext Total Score /20 /20 /15 /20 /25 /5 Grader

Discrete Structures. Fall Homework3

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Midterm 2 Exam Principles of Imperative Computation. Tuesday 31 st March, This exam is closed-book with one sheet of notes permitted.

CS 216 Exam 1 Fall SOLUTION

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

Computer Science 302 Spring 2018 Practice Examination for the Second Examination,

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Introduction to Data Structure

COS 226 Midterm Exam, Spring 2009

4.4 Algorithm Design Technique: Randomization

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 121: MIDTERM 2 Group March 12, 2014

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006

ECE242 Data Structures and Algorithms Fall 2008

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

( ) n 3. n 2 ( ) D. Ο

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:

PRACTICE MIDTERM EXAM #2

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

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

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

NATIONAL UNIVERSITY OF SINGAPORE

DATA STRUCTURES AND ALGORITHMS

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

COMP 250 Fall Midterm examination

Midterm 1 Solutions Principles of Imperative Computation. Thursday 6 th October, 2016

Largest Online Community of VU Students

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

Chapter 2: Complexity Analysis

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011

Data Structures and Algorithms Key to Homework 1

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

1 Inheritance (8 minutes, 9 points)

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.

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

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

Algorithms and Data Structures

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Transcription:

The University of British Columbia Computer Science 221: Discrete Math, Data Structures Midterm Examination, March 2, 2006. Instructor: E.M. Knorr Time: 75 minutes. Closed book. No notes. No cell phones. No calculators (you can leave answers in combinatorial form). Name (PRINT) (Last) (First) Student No Signature The examination has 7 pages, and that includes this cover sheet. Check that you have a complete paper. Print your name and ID at the top of this page, and provide your signature. Have your student ID ready. Since there are serial numbers on these pages, and to save you time, you do not have to print your name on each page. This is a closed book exam. No help sheet, and no calculators are permitted. You can leave your answers in combinatorial form. Work quickly and do the easy questions first. Part marks are available. Be sure to show your work. The marks for each question are given in braces. Do not spend too much time on any one question. Marks Page Max. Achieved 2 13 3 14 4 10 5 8 6 11 7 10 Total 66 To minimize disruptions during the exam, please avoid asking the invigilators for help, tips, or explanations. Please write down any reasonable assumptions that you are making, if you believe that a question is ambiguous.

1. 6 marks} Suppose we have 3 sets: A=1, 2, 3, 4, 5}, B=2, 4, 6, 8, 10}, and C=3, 5, 9, 10}. Find expressions, if they exist, which are equal to each of the following sets. These expressions must be expressed in terms of the set operators: union?, intersection, and set difference. Example: 2, 3, 4, 5, 6, 8, 10}: This set can be represented by (A C)? B. Give such expressions for: (a) 6, 8}: (b) 2, 3, 4, 5, 9, 10}: 2. 7 marks} A security guard has m keys and n locks, but forgot which keys open which locks. (The keys are just for these locks.) Suppose that there are exactly 2 keys that open the same lock, while the rest of the keys open one and only one lock. a) If m = 6 and n = 5, can the guard open all of the locks? Briefly justify your answer. b) If m = 6 and n = 5, is this function one-to-one? Onto? No explanations are necessary. c) Give the best Big-O estimate for the worst-case number of steps required to open all the locks, given m keys and n locks (where exactly two of the keys open one lock, and all other keys open only one lock). No witnesses are required, but briefly justify your answer (by showing your calculation). Page 2

3. 4 marks} Suppose Wendy s restaurants offer 8 toppings for a hamburger: cheese, ketchup, lettuce, mayonnaise, mustard, onions, pickles, and tomatoes. At Wendy s, you can tell the server at the counter which combination of toppings, if any, that you would like to have on your hamburger. What is the number of different ways that a hamburger can be customized? (i.e., How many different ways are there to come up with hamburgers having different toppings?) We assume that the order of toppings doesn t matter, and you re limited to one unit of each topping (i.e., someone can t say, I want 4 pickles.) 4. 4 marks} Suppose that f(n) is Ω(g(n)), h(n) is Ω(g(n)), and k(n) is Ω(g(n)). Use the definition of Big-Ω to prove that f(n) + h(n) + k(n) is Ω(g(n)). 5. 6 marks} a) How many 3-person committees can be chosen from a set of 6 people, if there are no restrictions as to who can be on the 3-person committee? b) Suppose that 6 boys and 6 girls have signed up to be on a co-ed softball team. Suppose the rules state that only 7 players (from this group of 12) can play in a given game. For a given game, how many ways are there to select a team of 7 players if the rules also state that at least 3 of the 7 players must be girls? Page 3

6. 10 marks} The following C++ function traverses a doubly-linked list consisting of 0 or more nodes from the current node, in the direction indicated by the input parameter (going left, or going right). For example, if you are at node Susan, and you re supposed to go left, then, on the screen, print out all the names found in the nodes from the one before Susan to the start of the list, in that order (but do not include Susan (in the current node). The same idea applies when going to the right. The following Node code is correct: struct Node string name; Node * prev; Node * next; }; If curr is a Node pointer, then cout << curr->name << endl; prints out the name. Finish the following function. There is no dummy node at the start or the end of the list, so you ll have to test for where the list ends. Note that the function returns the number of names printed. int printnodesinonedirection(node * curr, char LeftOrRight) // POST-CONDITION: This function starts at node curr and then prints out // all the names in the nodes to the left ( L ) or right ( R ) of curr (but // excluding the name in curr. The function returns a count of the number // of names printed on the screen. // PRE-CONDITION: curr is NULL, or points to a valid Node shown above; // LeftOrRight is either L or R /* Declare any needed variables here. Follow this with your code. (Some code is provided further below.) */ if (LeftOrRight == L ) /* print out all the names of the nodes to the left of curr s node */ More space is on the next page. Page 4

7. 4 marks} Which of the following statements about stacks, queues, and deques are true? Circle all correct answers. a) Stacks and queues can be implemented using arrays, but deques cannot be. b) A queue allows a user to retrieve nodes using the FIFO principle, in O(1) time. c) A stack allows a user to retrieve nodes using the LIFO principle, in O(1) time. d) Consider an array having a capacity of n elements, and assume that no more than one element can fit into a cell of the array. It is clear that we cannot store more than n elements in such an ordinary array. On the other hand, if the array is a circular array, then we can store more than n entries in it at any given time because we can make use of the modulus operator. e) With a doubly-linked list, it is not possible to keep the nodes sorted, unless there is only 1 element in the list (or unless it s an empty list). 8. 0 marks} The women s Canadian Olympic hockey team did really well this year, winning a gold medal! The men s Canadian Olympic hockey team, however, didn t do very well, scoring exactly 0 goals in 3 of their last 4 games and they received no medal. What was your opinion of the performance of the men s Canadian Olympic hockey team? a) I m disappointed, especially since the men collectively make $95 million per year in the NHL. b) I m downright angry. c) I m not at all surprised because. d) The men did reasonably well, given the time constraints, pressure, etc. Besides, I expect that we ll strike gold at the 2010 Olympics in Vancouver. e) I don t have an opinion (or I don t care, or I don t follow hockey). 9. 4 marks} Which of the following statements are true about complexity? Circle all correct answers. a) Suppose you compute that f(n) is O(n), and that f(n) is Ω(lg n). Then it is the case that f(n) is Θ(n). b) For all comparison based sorts, an upper bound on the number of steps taken to sort n elements is Ω(n lg n). c) Insertion sort is a recursive algorithm, and it has worst-case complexity Θ(n 2 ). d) Suppose Mergesort is used to sort an array A (containing unique elements) into ascending order. Then, a binary search on the result has complexity Θ(lg n). e) A Θ(n 2 ) algorithm is likely to outperform a Θ(n 3/2 ) algorithm. Page 5

10. 6 marks} Compute Big-Theta for the number of dollar signs ($) printed by the following algorithm, as a function of N. Justify your answer by briefly explaining your work (i.e., by showing your calculations). It is not necessary to compute witnesses. Algorithm MyCalc(N) written in C++ style: j = 0; n = N; while (n > 1) n = n / 32; j++; } for (w = 0; w < (N/3 + 32); w++) for (k = 1; k <= j*n; k++) cout << $ ; cout << endl; 11. 5 marks} Give a recursive algorithm to compute the product of 2 positive integers m and n using only addition. Page 6

12. 4 marks} How many non-negative integer solutions are there to the following equation? x 1 + x 2 + x 3 + x 4 + x 5 = 18 such that x i i (the letter i not one ) 13. 6 marks} This question is about program correctness. Use a loop invariant to prove that the following C++ code function correctly computes x n where n 1. (You can assume that the result is an integer and will fit into an integer.) int computeproduct(int x, int n) int product = 1; int k = 1; while (k <= n) product = product * x; k++; } } return product; Page 7