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

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

Final Examination CSE 100 UCSD (Practice)

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

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

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

Computer Science E-22 Practice Final Exam

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

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

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

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

CS171 Final Practice Exam

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

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

CS171 Final Practice Exam

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

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

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

Review for Midterm Exam

Course Review for Finals. Cpt S 223 Fall 2008

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

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

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

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

CSE332 Summer 2012 Final Exam, August 15, 2012

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

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

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

CS302 Data Structures using C++

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

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

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

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

CISC-235* Test #3 March 19, 2018

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Course Review. Cpt S 223 Fall 2009

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

CPSC 331 Term Test #2 March 26, 2007

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

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

) $ f ( n) " %( g( n)

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

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

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

CSE373 Spring 2015: Final

CSL 201 Data Structures Mid-Semester Exam minutes

Question Paper Code : 97044

Final exam. CS 2110, December 15, 2016, 9:00AM

Second Examination Solution

University of California, Berkeley. CS 186 Introduction to Databases, Spring 2014, Prof. Dan Olteanu MIDTERM

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A Previous CS 310 Final Exam

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

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

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

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

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

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

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?

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

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

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

About this exam review

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

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

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

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

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Data Structures Question Bank Multiple Choice

CSc 225 Algorithms and Data Structures I Algorithm Analysis

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

CSE332 Summer 2010: Final Exam

12 Abstract Data Types

CS 373: Combinatorial Algorithms, Spring 1999

Computer Science Foundation Exam

Total Score /1 /20 /41 /15 /23 Grader

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Solutions to Exam Data structures (X and NV)

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

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

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

Closed Computer and Book 1 Double-sided sheet of notes allowed staple to your test when done

CSC2100-Data Structures

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

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

Largest Online Community of VU Students

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

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Algorithm Design (8) Graph Algorithms 1/2

CSE332 Summer 2010: Midterm Exam Sample Solutions

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

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

DATA STRUCTURES AND ALGORITHMS

Data Structures and Algorithms

Transcription:

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: This exam is CLOSED book and notes. Instructions The exam consists of six questions on 11 pages. Please answer all questions on this exam sheet. Please read through all questions carefully and be sure that you understand the instructions before working on a problem. The exam will be scored out of 100 possible points. The questions are not of equal weight, but the weight is indicative of the difficulty. You have until 11:00 AM to complete the exam. Please budget your time wisely! Please ask if you have any questions. GOOD LUCK! 1.) (16 points) 2.) (13 points) 3.) (18 points) 4.) (17 points) 5.) (12 points) 6.) (24 points) 1

Question 1: Short answer (2 pts each). 1. T/F: In hashing, use of Horner s method can avoid arithmetic overflow. 2. T/F: It would be appropriate to have a Giraffe Class inherit from a Mammal Class. 3. T/F: It would be appropriate to have a Bird Class inherit from a Beak Class. 4. T/F: Queue insertion and stack insertion are both O(1) operations. 5. In big-o notation, how large is the sum 1 + 2 + 3 + 4 +... + N? 6. In big-o notation, how many terms are in the sequence 1, 2, 4,..., N, N, N? 4 2 7. Name a data structure used for fast indexing in large databases. 8. Which data structure is used by routers to represent Internet graphs. 2

Question 2 (13 pts): Hashing (a.) (5 pts) Diagram where the following set of input keys will be placed into a standard 7- element array-based hash table when we use the following hash function and we employ standard linear probing when a collision occurs. h(key) = key % 7; Input keys: 4, 10, 11, 24, 20 (b.) (3 pts) What is the load factor when this set of keys is inserted into this hash table? (c.) (5 pts) Assume that in our hash table implementation, each entry either contains a key or is marked as empty (i.e. cells cannot be marked as deleted). For each of the five keys, specify whether it cannot be removed (i.e. have its cell marked as empty) since that would result in searches for other valid keys to fail, or whether it can safely be removed. Treat each key removal independently from all other removals. 3

Question 3 (18 pts): Fancy Data Structures. (a.) (6 pts) Here is a picture of a 3-level B-Tree from our textbook. What is the shortest sequence of insertions needed to cause this B-Tree to break into 4 levels? Write down the insertions in your sequence explicitly. Note to 11 students: We didn t cover B-Trees this semester, but I could ask a similar question aobout 2-3 trees, say using the picture on p. 330. (b.) (5 pts) Here is a picture of a skip list from our textbook. Blacken all the edges that are inspected when an unsuccessful search for 46 is performed. Note to 11 students: Not covered this semester. 4

(c.) (7 pts) Here is a picture of a Red-Black tree from our textbook. (Assume the final tree on the Figure on p. 346 was provided). Specify a key whose insertion would trigger a double-rotation, and show the subtree after double-rotation is performed. 5

Question 4 (17 pts): Graphs. (a.) (4 pts) Provide the adjacency matrix representation for the undirected graph shown above. (Assume a graph like the first seven nodes of tinyg.txt on p. 428 was provided). (b.) (4 pts) Specify a possible order in which nodes are visited in a breadth-first search traversal of the graph starting from node 2. (c.) (4 pts) Specify a possible order in which nodes are visited in a depth-first search traversal of the graph starting from node 6. 6

(d.) (5 pts) Now consider the same graph with the addition of edge weights as shown. Highlight those edges which are in the minimum spanning tree of this graph (or draw the spanning tree in a separate picture). (Use weights of i + j for edges connecting nodes i and j). 7

Question 5 (12 pts): Heap Implementation. Assume that a max-heap (biggest on top) of integers is implemented using the following class. public class Heap { int MAX_HEAP; // maximum # of items in the heap int [] items; // set of items in the heap int size; // # of items in the heap }; (a.) (3 pts) Sketch a possible layout of the set of keys {72, 16, 42, 33, 81, 10, 23} when stored into a Heap named X with MAX_HEAP = 10. (b.) (9 pts) Write the Insert method for the Heap class. void Insert (int newitem) { } 8

Question 6 (24 pts): Set Implementations. A set is a collection of distinct objects, often referred to as set elements. In this question, we will consider data structures for representing sets of positive integers. Three important operations on sets are union, set difference, and membership. The union of two sets A and B is the set of elements in either A or B (without duplicates). The set difference A \ B is the set of elements in A but not in B. A membership test asks whether a given element is in a given set. For example, consider the five-element set A = {5, 8, 13, 25, 92} and the four-element set B = {3, 5, 8, 13}. The union of A and B is {3, 5, 8, 13, 25, 92}, and A \ B = {25, 92}. Element 3 is a member of B, but not of A. (a.) (3 pts) One easy way to implement sets of positive integers is via a linked list with elements in sorted order. With this implementation, what is the worst-case running time of membership, union, and set difference on sets of size N? (b.) (10 pts) Now assume you have the following class declarations for sorted linked list implementation of Sets (only the relevant parts for this question are provided). public class ListNode { int item; ListNode next; } class List {... ListNode head; } class Set {... List l; } On the following page, complete the skeleton function declaration to compute (and return) the set difference of two Sets. For simplicity, you may assume that this is not a method of the class Set, and do not bother using any of the List routines (just access list items by traversing next pointers). 9

Set compute_difference (Set A, Set B) { Set result = new Set(); // assume the constructor correctly initializes // the member variable l to an empty list. ListNode Aptr = A.l.head; ListNode Bptr = B.l.head; // your code here } return result; 10

(c.) (3 pts) Often, sets have values over a finite range, like positive integers between 0 and M, inclusive, for a small to moderate value of M. When this is the case, an array-based implementation is a reasonable choice. For example, a bit array implementation of a set might use an array A, storing the value 1 in A[i] if i is an element of the set, and 0 otherwise. Using this definition, sketch the bit array used to represent the set {0, 2, 5, 7} when M is 8. (d.) (3 pts) What are the running times of the three set operations using this bit array implementation (as a function of M)? (e.) (5 pts) Now assume M is much larger than N. Sketch a data structure that achieves the same expected running times as the bit array implementation of a set of N elements, but does so using only O(N) space, not O(M) space. Make sure your data structure can still handle the three set operations. 11