CISC-235* Test #3 March 19, 2018

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

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

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

Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect).

Data Structures and Algorithms 2018

Hash Tables Outline. Definition Hash functions Open hashing Closed hashing. Efficiency. collision resolution techniques. EECS 268 Programming II 1

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

Computer Science Spring 2005 Final Examination, May 12, 2005

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Priority queues. Priority queues. Priority queue operations

Final Examination CSE 100 UCSD (Practice)

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

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Test points UTA Student ID #

INSTITUTE OF AERONAUTICAL ENGINEERING

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

CS 261 Spring 2013 Midterm

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

CSCI E 119 Section Notes Section 11 Solutions

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

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

FINAL EXAM REVIEW CS 200 RECITATIOIN 14

Computer Science E-22 Practice Final Exam

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials)

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

Algorithm Design (8) Graph Algorithms 1/2

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

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

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

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

Exam Datenstrukturen und Algorithmen D-INFK

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

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

Name: After line 1: After line 3: After line 5: After line 8: After line 11:

Computer Science Foundation Exam

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

CSE373 Winter 2014, Final Examination March 18, 2014 Please do not turn the page until the bell rings.

Course Review. Cpt S 223 Fall 2009

CISC-235* Test #2 October 15, 2018

Chapter 10. Fundamental Network Algorithms. M. E. J. Newman. May 6, M. E. J. Newman Chapter 10 May 6, / 33

Understand how to deal with collisions

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

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

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Prelim 2 Solution. CS 2110, April 26, 2016, 5:30 PM

Exam Data structures DAT036/DAT037/DIT960

Section 05: Solutions

CSE 332: Data Structures & Parallelism Lecture 3: Priority Queues. Ruth Anderson Winter 2019

list<t>::const_iterator it1 = lst.begin(); // points to first element list<t>::const_iterator it2 = lst.begin(); // points to second element it2++;

CS 206 Introduction to Computer Science II

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

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

Midterm solutions. n f 3 (n) = 3

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

CSL 201 Data Structures Mid-Semester Exam minutes

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

Basic Search Algorithms

Hash Tables. Hashing Probing Separate Chaining Hash Function

Hash Tables. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited

Computer Science 302 Fall 2009 (Practice) Second Examination, October 15, 2009

Hashing for searching

CS 202, Fall 2017 Homework #4 Balanced Search Trees and Hashing Due Date: December 18, 2017

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

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

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 1st June 2017 Time: 14:00-16:00

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Hash Tables and Hash Functions

1 Heaps. 1.1 What is a heap? 1.2 Representing a Heap. CS 124 Section #2 Heaps and Graphs 2/5/18

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

CS 310 Hash Tables, Page 1. Hash Tables. CS 310 Hash Tables, Page 2

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Midterm Exam Amy Murphy 6 March 2002

1. AVL Trees (10 Points)

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Data Structures. Topic #6

UNIT III BALANCED SEARCH TREES AND INDEXING

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

Exam Datenstrukturen und Algorithmen D-INFK

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

COSC160: Data Structures Hashing Structures. Jeremy Bolton, PhD Assistant Teaching Professor

MA/CSSE 473 Day 23. Binary (max) Heap Quick Review

CSC2100-Data Structures

Total Score /15 /20 /30 /10 /5 /20 Grader

CS 170 Spring 2000 Solutions and grading standards for exam 1 Clancy

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Practice Midterm Exam Solutions

Dijkstra s Shortest Path Algorithm

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Recall: Properties of B-Trees

CSE 373 Midterm 2 2/27/06 Sample Solution. Question 1. (6 points) (a) What is the load factor of a hash table? (Give a definition.

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

Total Score /15 /20 /30 /10 /5 /20 Grader

Depth First Search A B C D E F G A B C 5 D E F 3 2 G 2 3

Priority Queues and Binary Heaps

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

Inverted Indexes. Indexing and Searching, Modern Information Retrieval, Addison Wesley, 2010 p. 5

Transcription:

CISC-235* Test #3 March 19, 2018 Student Number (Required) Name (Optional) This is a closed book test. You may not refer to any resources. This is a 50 minute test. Please write your answers in ink. Pencil answers will be marked, but will not be re-marked under any circumstances. The test will be marked out of 50. Question 1 /12 Question 2 /12 Question 3 /12 Question 4 /12 Question 5 /2 TOTAL /50 You oughta be thankful, a whole heaping lot, For the places and people you're lucky you're not! Dr. Seuss

Question 1 (12 marks) Suppose we are hashing a set of 10,000 items, each identified by a 9-digit integer key. Explain why hashing strategy for this situation. with quadratic probing is not a good Solution: With 9-digit keys, the sum of the digits of a key will always be in the range [0..81] Since we have 10,000 items we are guaranteed that almost all insertions will find that their first location is already occupied (ie. there is a collision). The quadratic probing collision technique follows a fixed probing sequence for each original address, so this will result in only 82 different probing sequences. With 10,000 items, the average probing sequence length will be very high. Marking: Identify the problem of all 10,000 keys being hashed into locations 0 to 81 (or the first few addresses in the table ) : 8 Identify the problem of quadratic probing only producing a small number of probing sequences : 4 Give part marks for answers that refer to clustering of the keys without clearly expressing the way this hashing function and collision resolution technique produce many collisions.

Question 2 (12 marks) Many computer simulations employ Future Events. Upcoming events in the simulation (such as Customer will arrive at time 9:17 ) are stored in a data structure. When the simulated clock advances to the time of the earliest Future Event, that event is removed from the structure and processed. New future events, with their specified time of occurrence, are frequently added to the structure. What data structure would you use to organize the set of Future Events, and why would you choose it? Solution: The most natural answer (given the subject matter of this test) is a Priority Queue implemented using a Heap. Students could also just say a Heap, using the time of the future event as the priority. It is important to note that we would need to invert the ordering rule: we want the smallest (ie. earliest) time at the top of the heap. This permits all operations in O(log n) time. Another plausible answer is a Balanced Binary Search Tree (such as a Red- Black tree) with the time of the future events used for the ordering. This also permits all operations in O(log n) time, although the balancing operations add overhead. Also, Red-Black Trees do not permit duplicate values so we would need to be sure there cannot be two future events with the same time value. Students may misunderstand the question and assume that each new future event has a time that is the time of the previous one. If this were the case, a simple queue would suffice.

Marking: A data structure that permits O(log n) time for the operations and correctly identifies the ordering criterion (based on the times of the future events) : 6 Explanation: A data structure that permits O(log n) time for the operations but does not identify the ordering criterion : 4 A simple queue, based on misunderstanding the question as described above : 3 A data structure that gives O(n) time or worse : 1 Correctly identifying valid reasons for choosing the data structure they chose (students who misunderstood the question can get full marks here) : 6 Stating reasons that do not actually apply to the data structure they chose : 3 Stating invalid reasons, vague reasons (eg it s better ) : 1 No reasons : 0

Question 3 (12 marks) Suppose you are asked to create a data structure to store a priority queue for an application in which the only possible priorities are 11, 32, 79 and 100000. The necessary operations are: add a new item to the priority queue locate and extract the item with the highest priority currently in the queue. If two items are tied for highest priority, the one that was added earlier should be the one chosen. Your goal is to minimize the time complexity of the operations. Describe the data structure (or structures) you would use in this situation. Explain your answer. Solution: (This is my solution... there may be others just as efficient) Create an array A with four elements, each of which is a pointer to a list of items. A[0] points to a list of all items with priority 100000, A[1] points to a list of all items with priority 79, A[2] points to a list of all items with priority 32, and A[3] points to a list of all items with priority 11. To add a new item to the priority queue, append it to the end of the list associated with its priority. This can be done in constant time if we maintain pointers to the last node in each of the lists. To extract the highest priority item with the earliest arrive, we just return the first element in the first non-empty list. Due to the way the lists are built, this will guarantee that the first-arrival breaks ties rule is satisfied. This is also achieved in constant time. Thus this data structure permits both of the required operations in constant time.

Marking: Data Structure: Something similar to the above that gives O(1) time for the operations : 6 Something different that gives O(1) time for the operations : 6 Something that gives O(log n) for the operations : 3 Something that gives O(n) or worse for the operations : 1 Explanation: Correctly identifying the complexity of the operations : 6 Not mentioning complexity but commenting on simplicity of operations : 4 Incorrectly identifying the complexity of the operations : 3 Some completely different rationale :? (grade depending on how much sense it makes... feel free to ask me)

Question 4 (12 marks) Suppose you have a graph that represents a large, many-roomed house. Each room has an identifying number from 1 to n. The vertices of the graph (also numbered 1 to n) represent the rooms and the edges represent doors between the rooms. Some rooms have pots of gold in them (left behind on March 17 by partying leprechauns). Each room also has a surveillance camera which will show you the contents of the room. You can access all the cameras through your smartphone. You are in a room with no gold. Your task is to use the graph and the cameras to find the shortest sequence of rooms to walk through that will lead you to a room that contains gold. What data structure will you choose to represent the graph, and why? Solution: The most appropriate data structure is a set of adjacency lists. Finding the shortest path to gold can be done with the Breadth-First Search (BFS) Algorithm. The adjacency list representation of the graph lets us implement BFS in O(m) time.

Marking: Choice of data structure: Adjacency Lists : 6 Adjacency Matrix : 3 Other : 1 Reason: Efficient implementation of search algorithm : 6 Other plausible reasons (simplicity, ease of access to data, etc) : 3 Poor reason ( it s better, etc) : 1

Question 5 (2 marks) True or False: The Max Heap data structure was invented by a researcher named Maxwell Heap. True FALSE Solution: False Marking: False 2 True 0 No answer 0