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

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

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

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

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

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

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

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

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

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

Practice Midterm Exam Solutions

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

CSE373 Winter 2014, Midterm Examination January 29, 2014

Course Review. Cpt S 223 Fall 2009

PROBLEM 1 : (And the winner is...(12 points)) Assume you are considering the implementation of a priority queue that will always give you the smallest

ECE250: Algorithms and Data Structures Midterm Review

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

Computer Science Foundation Exam

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

CSE373 Fall 2013, Midterm Examination October 18, 2013

Recitation 9. Prelim Review

CSE332 Summer 2010: Midterm Exam Sample Solutions

Course Review. Cpt S 223 Fall 2010

ECE242 Data Structures and Algorithms Fall 2008

CSL 201 Data Structures Mid-Semester Exam minutes

COS 226 Midterm Exam, Spring 2009

CSE 332 Autumn 2016 Final Exam (closed book, closed notes, no calculators)

CSE wi: Practice Midterm

Part 1: Multiple Choice Circle only ONE answer. Each multiple choice question is worth 3.5 marks.

Computer Science E-22 Practice Final Exam

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

Course Review for Finals. Cpt S 223 Fall 2008

Section 1: True / False (1 point each, 15 pts total)

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

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

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

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

UNIT III BALANCED SEARCH TREES AND INDEXING

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

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

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

CSE 373 Spring Midterm. Friday April 21st

CS171 Final Practice Exam

CS171 Final Practice Exam

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

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

Data Structures Question Bank Multiple Choice

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

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

Introduction to Algorithms March 12, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1

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

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

CS 216 Exam 1 Fall SOLUTION

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

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

Quiz 1 Practice Problems

CS301 - Data Structures Glossary By

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

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

1. Attempt any three of the following: 15

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

Computer Science Foundation Exam

CPSC 331 Term Test #2 March 26, 2007

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

INSTITUTE OF AERONAUTICAL ENGINEERING

Priority Queues. Lecture15: Heaps. Priority Queue ADT. Sequence based Priority Queue

Second Examination Solution

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

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

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

CSE 332 Winter 2018 Final Exam (closed book, closed notes, no calculators)

Prelim 2. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs. Max Score Grader

Final Examination CSE 100 UCSD (Practice)

Sample Exam 1 Questions

Quiz 1 Practice Problems

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

THE UNIVERSITY OF WESTERN AUSTRALIA

Prelim 2, CS2110. SOLUTION

Basic Data Structures (Version 7) Name:

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

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSCE 2014 Final Exam Spring Version A

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

We've tried to include the common errors and grading standard for every question.

O(n): printing a list of n items to the screen, looking at each item once.

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Recall from Last Time: Big-Oh Notation

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

Binary Heaps. COL 106 Shweta Agrawal and Amit Kumar

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

COMP171 Data Structures and Algorithms Fall 2006 Midterm Examination

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

1. AVL Trees (10 Points)

CSE 373 NOVEMBER 8 TH COMPARISON SORTS

Module 2: Classical Algorithm Design Techniques

Transcription:

_ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give partial credit based on the work you write down, so show your work! Use only the data structures and algorithms we have discussed in class so far. You are forbidden to communicate with anyone about the exam until after 1:30pm. Note: For questions where you are drawing pictures, please circle your final answer. Good Luck! Total: 100 points. Time: 50 minutes. Question Max Points 1 18 2 8 3 10 4 8 5 10 6 9 7 11 8 16 9 10 Total 100 Score

1. (18 pts) Big-Oh (2 pts each) For each of the operations/functions given below, indicate the tightest bound possible (in other words, giving O(2 N ) as the answer to every question is not likely to result in many points). Unless otherwise specified, all logs are base 2. Your answer should be as tight and simple as possible. For questions that ask about running time of operations, assume that the most efficient implementation is used. For arraybased structures, assume that the underlying array is large enough. For questions about hash tables, assume that no values have been deleted (lazily or otherwise). You do not need to explain your answer. a) Pop in a stack containing N elements implemented using an array (worst case) b) Find in an open addressing hash table containing N elements where linear probing is used to resolve collisions (worst case). Tablesize = N 2 c) Merging two binary min heaps containing N elements each. (worst case) d) Determining what the 10 largest items are in an open addressing hash table containing N elements where quadratic probing is used to resolve collision (worst case). Tablesize = 2*N. e)t(n) = T(N/2) + 100 f) f(n) = log log (N + N) + log 2 N g) Insert in a separate chaining hash table containing N elements where each bucket points to a sorted linked list (worst case) Tablesize = N 2 h) f(n) = N log 2 N + N 2 log N i) decreasekey (k, amount) on a binary min heap containing N elements. Assume you have a reference to the key k that should be decreased. (worst case) 2 of 12

2. (8 pts) Big-Oh and Run Time Analysis: Describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. Your answer should be as tight and simple as possible. Showing your work is not required I. void happy (int n, int sum) { int k = 1; while (k < n) { for (int i = 0; i < k; i++) { sum++; k++; for (int j = n; j > 0; j--) { sum++; II. int smiley (int n) { if (n < 5) return n * n; else { for (int i = 0; i < 10,000; i++) { print i return smiley (n / 2); III. void sunny (int n, int sum) { for (int i = 1; i < n * n; i++) { if (sum > 10) { for (int j = 0; j < n; j++) { sum++; else { sum++; IV. void funny (int n, int sum) { for (int i = 0; i < n * n; i++) { if (i % 10 == 0) { for (int j = 0; j < i; j++) { sum++ Runtime: Page 3 of 12

3. (10 pts) Big-O, Big Ω, Big (2 pts each) For parts (a) (e) circle ALL of the items that are TRUE. You do not need to show any work or give an explanation. a) N 2 + N 2 log N is: Ω (N 2 ) O (N 2 ) (N 2 ) None of these b) N log N + log (log N) + 300 is: Ω (log N) O (log N) (log N) None of these c) N 2 log N + N 4 is: Ω (N 3 ) O (N 5 ) (N 4 ) None of these d) N log 2 N + N 2 log N is: Ω (N 2 ) O (N 2 ) (N 2 log N) None of these e) If f(n) is O(g(n)) and g(n) is O(h(n)), which of the following is correct? (circle all that are true) i. f(n) * g(n) is O( f(n) * g(n) ) ii. f(n) + g(n) is O( min(g(n), h(n)) ) iii. iv. f(n) is O(h(n)) h(n) is O(f(n)) v. none of the above 4 of 12

4. (8 pts) Draw the AVL tree that results from inserting the keys 3, 1, 4, 5, 9, 2, 6, 7, 8 in that order into an initially empty AVL tree. You are only required to show the final tree, although if you draw intermediate trees, please circle your final result for ANY credit. Page 5 of 12

5. (10 pts) Data Structure Choice Select the best (in terms of run-time) data structure to use in the following scenarios and give a one sentence description of why you chose it. Choose from the following data structures (each of which may be used more than once): Move-to-front List (as in project 2), Stack, Queue, AVL Tree, Heap, Hash Table, B-tree a) Selecting the order of messages to send in a network when some messages require a faster delivery than others. New messages are always coming in. Heap Messages have a notion of priority. b) Tracking the orders placed at a counter in a sandwich shop. Queue customer orders should be handled in a FIFO manner. c) Tracking the roster of Seahawks players. Individual player records are occasionally requested by the player s name. Requesting the entire list of players sorted by player names is the most common operation. New players are added to the roster fairly often. AVL tree was expected answer because returning a list of players in sorted order is best supported using an inorder traversal in O(N). Some folks seemed to think that B-tree would also be appropriate. We did not intend the number of players on the Seahawks roster to be so big as to require using lots of memory but we accepted B-trees as well. We did not talk about it but B-trees can also support listing all elements in sorted order efficiently O(N). d) A company has a huge amount of data stored on external servers. They have even more data to add and will be performing many insert operations, which they want to be fast. B-tree Best for inserting data when it must be stored on external disks. e) A company has a large amount of data that is not comparable. They want to use a data structure that gives them the fastest possible find operation. Should they use an AVL tree or a Move-to-front List? Move-to-front You cannot use AVL if data is not comparable. 6 of 12

6. (9 pts) Hashing Name: Assuming inputs are all 3-digit numbers and d0 is the digit in the rightmost position. (e.g. the three digit number 456 has these digits: d2=4, d1=5, d0=6), you are given 3 possible hash functions: h1(x) = d2 + d1 + d0 h2(x) = d2 + d1 h3(x) = d2 a) For a table of size 10 and the following 6 inputs, rank the 3 hash functions in order from best (least collisions) to worst (most collisions). Assume separate chaining and for the purposes of this question, take number of collisions to mean number of items not in a bucket by themselves. 160 610 345 254 532 449 Best: 2 nd Best: Worst: b) Give the load factor if each of the hash functions above is used on the inputs given above on a hash table of size 10: h1: h2: h3: c) Rank the hash functions again by the number of expected collisions for a random set of inputs: Best: 2 nd Best: Worst: Page 7 of 12

7. (11 pts) Min Heaps - a) (6 pts) As discussed on homework 2, a three-heap with n elements can be stored in an array A, where A[0] contains the root of the tree. Draw the three-heap that results from inserting 5, 2, 8, 3, 6, 4, 9, 7, 1 in that order into an initially empty three-heap. You do not need to show the array representation of the heap. You are only required to show the final tree, although if you draw intermediate trees, please circle your final result for ANY credit. 8 of 12

7. Min Heaps (continued) b) (2 pts) Draw the result of doing 1 deletemin on the heap you created in part a. You are only required to show the final tree, although if you draw intermediate trees, please circle your final result for ANY credit. c) (3 pts) Assuming that elements are placed in the array starting at location A[0], give expressions to calculate the left, middle, and right children of the element stored in A[i]: Left child: Middle child: Right child: Page 9 of 12

8. (16 points) Data Structure Analysis Your co-worker has created a new data structure for storing positive integers and needs your help evaluating it. The structure consists of an unsorted array, where each location in the array points to an AVL tree containing at most 100 integers, inserted as follows. Integers will be placed in a bucket with other integers containing the same digits in the hundred and above positions (i.e. ignoring digits in the 10 s place and the 1 s place). When an integer is inserted, first it is divided by 100 (not mod!) and then an appropriate array location is searched for. If an appropriate array location exists, the integer is inserted into the AVL tree linked there. If an appropriate array location does not yet exist then one is added at the end of the list and the integer is inserted as the first value in the AVL tree linked there. Below is an example of a structure that would be created if the integers: 501, 14, 378, 2154, 410, 523, 400, and 499 had been inserted in that order. In this example, the first bucket would hold integers in the range 500-599, the second in the range 0-99, the third in the range 300-399, the fourth in the range 2100-2199, and the fifth in range 400-499. 500 0 300 2100 14 378 501 2154 523 400 410 400 499 Each location in the array will contain two fields: an integer representing the smallest value that could possibly be stored in this AVL tree and a pointer to an AVL tree. You may assume that no duplicate values will ever be inserted and that the original array will always be large enough. a) What would be the worst case big-o run-time of a find operation on this data structure? Explain your answer briefly. O(N) Worst case is each integer is in its own bucket (so N buckets), and the bucket you need is the last one in the array (this is basically an unsorted array). This scenario has just one element per bucket, but even a maximally full AVL tree has find of O(log 100), not O(log N) as many people said, so overall O(N+ log 100) O(N) b) What would be the worst case big-o run-time of an insert operation on this data structure? Explain your answer briefly. O(N) Same as above to find the place to put the integer. If no appropriate bucket is found, constant time to create new bucket at end and add item into the AVL tree. 10 of 12

8. Data Structure Analysis (continued) Your co-worker suggests a couple of modifications to the original data structure: Option 1: Instead of an unsorted array, use a move-to-front list created with linked list nodes (as in Project 2). c) Worst case big-o run-time of a find operation? Explain your answer briefly. O(N) Still an unsorted list. Worst case is every integer in its own bucket and you are looking for the least-recently used bucket or one that is not present do must traverse the whole list containing N buckets. Find on these AVL trees is O(1). d) Worst case big-o run-time of an insert operation? Explain your answer briefly. O(N) Still an unsorted list. Worst case is every integer in its own bucket and you are looking for the least-recently used bucket or one that is not present. Have to first find the appropriate bucket or examine them all to determine you need to create a new one. If needed, you should create the new bucket at the front of the list, but you must search the entire list, O(N), to determine that you need to create it. Insert into an AVL tree containing a max of 100 integers is O(1). Option 2: Instead of an unsorted array, use a sorted array. e) Worst case big-o run-time of a find operation? Explain your answer briefly. O(log N) Worst case is every integer in its own bucket, so N buckets. Can do a binary search on sorted array to find correct bucket. Then search on these AVL trees is constant time. f) Worst case big-o run-time of an insert operation? Explain your answer briefly. O(N) Worst case is every integer in its own bucket, so N buckets. Can do a binary search on sorted array to find correct bucket. In worst case the bucket we want is not present and we need to insert it at the front and shift all buckets down O(N). Then insert into these AVL trees is constant time. You propose that your co-worker forget this idea completely and just use a separate chaining hash table of size N, where each bucket points to an AVL tree. g) Worst case big-o run-time of a find operation? Explain your answer briefly. O(log N) Worst case is every integer in the same hash table bucket. Finding correct hash table bucket is O(1). Then search on an AVL tree containing N items is O(log N). h) Worst case big-o run-time of an insert operation? Explain your answer briefly. O(log N) Worst case is every integer in the same hash table bucket. Finding correct hash table bucket is O(1). Then insert on an AVL tree containing N items is O(log N). Page 11 of 12

9. (8 pts) B-trees a) (2pts) In the B-Tree shown below, please write in the appropriate values for the interior nodes. b) (2 pts) Based on the picture below, what are the values for M and L? M = L = c) (4 pts) Starting with the B-tree shown below, insert 61. Draw and circle the resulting tree (including values for interior nodes) below. Use the method for insertion described in lecture and used on homework. 5 26 50 71 86 10 29 52 78 97 32 60 12 of 12