Computer Science E-22 Practice Final Exam

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

Computer Science E-119 Practice Midterm

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

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

Data Structures Question Bank Multiple Choice

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

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

Computer Science E-119 Fall Problem Set 4. Due prior to lecture on Wednesday, November 28

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

Recitation 9. Prelim Review

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?

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

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

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

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

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

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

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

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

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

Final Examination CSE 100 UCSD (Practice)

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

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

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Course Review for Finals. Cpt S 223 Fall 2008

INSTITUTE OF AERONAUTICAL ENGINEERING

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

Summer Final Exam Review Session August 5, 2009

CS171 Final Practice Exam

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

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

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))

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

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

Q1 Q2 Q3 Q4 Q5 Q6 Total

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

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

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

MIDTERM Preparation. CSS 343: Data Structures Algorithms, and Discrete Math II

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

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

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

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

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

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

CSCE 2014 Final Exam Spring Version A

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

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Basic Data Structures (Version 7) Name:

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

CS301 - Data Structures Glossary By

Computer Science Foundation Exam

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

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

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

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

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

CS171 Final Practice Exam

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

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

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

Test #2. Login: 2 PROBLEM 1 : (Balance (6points)) Insert the following elements into an AVL tree. Make sure you show the tree before and after each ro

Computer Science Foundation Exam

// a stack is printed from bottom (leftmost) to top (rightmost) System.out.println(stk);

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

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

CMSC132, Practice Questions

a graph is a data structure made up of nodes in graph theory the links are normally called edges

Computer Science Spring 2005 Final Examination, May 12, 2005

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Midterm solutions. n f 3 (n) = 3

Binary Trees

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

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

AP Computer Science 4325

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

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

Analysis of Algorithms

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

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

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

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Department of Computer Science and Technology

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Part I: Short Answer (12 questions, 65 points total)

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

CS 216 Exam 1 Fall SOLUTION

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

Computer Science Foundation Exam

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

Topics for CSCI 151 Final Exam Wednesday, May 10

CSE 373 Spring Midterm. Friday April 21st

Computer Science Foundation Exam

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

Transcription:

name Computer Science E-22 This exam consists of three parts. Part I has 10 multiple-choice questions that you must complete. Part II consists of 4 multi-part problems, of which you must complete 3, and Part III consists of a single multi-part problem that you must complete. Show your work in Parts II and III so that partial credit may be awarded when necessary. You have two hours to complete the exam. The questions are worth a total of 100 points. In order to properly budget your time, plan on spending approximately one minute per point. You may use any notes, books, or other references at your disposal. However, do not waste too much time leafing through your materials. Please turn off all electronic devices (including cell phones) and put them away. Do all your work on the exam itself. Write clearly. Good luck! Important: Please put an X through the SCORE box for the problem from part II that you do not want us to grade. Problem Max. Score SCORE I 30 II-1 15 II-2 15 II-3 15 II-4 15 III 25 TOTAL 100 Important: Put an X through the empty SCORE box of the problem from Part II that you do not want us to grade. Answers to Part I: question #: 1 2 3 4 5 6 7 8 9 10 first choice: second choice: David G. Sullivan, Ph.D. page 1 of 14

Part I. Multiple-choice (3 pts. each). Specify up to two answers. Write your answers in the table at the bottom of the cover sheet. You will get one point for any problem in which your first choice is wrong but your second choice is correct. 1. Suppose that items A, B, C, D and E are pushed, in that order, onto an initially empty stack S. S is then popped four times; as each item is popped off, it is inserted into an initially empty queue. If two items are then removed from the queue, what is the next item that will be removed from the queue? A. item A B. item B C. item C D. item D E. item E 2. If the binary tree below is printed by a preorder traversal, what will the result be? 6 / \ 17 22 / \ / \ 9 4 16 12 A. 9 4 17 16 12 11 6 B. 9 17 6 4 16 22 12 C. 6 9 17 4 16 22 12 D. 6 17 22 9 4 16 12 E. 6 17 9 4 22 16 12 3. A graph implementation that uses a two-dimensional array to represent the edges would be most reasonable for which of the following cases? A. 1000 nodes, 1200 edges B. 100 nodes, 4000 edges C. 1000 nodes, 10000 edges D. 10 nodes, 20 edges E. none of these, since a graph can only be represented by a linked structure. David G. Sullivan, Ph.D. page 2 of 14

4. A binary tree is constructed of nodes that are instances of the following class: public class Node { public int val; public Node left; public Node right; } Consider the following method: public static Node mystery(node root) { if (root.right == null) return root; else return mystery(root.right); } You consult three supposedly tech-savvy consultants, and you get the following three opinions about what the method does when passed a reference to the root node of a binary tree: I. It returns the last node visited by an inorder traversal II. It returns the last node visited by a postorder traversal III. It returns the last node visited by a level-order traversal Which of these opinions is correct regardless of the contents of the tree? A. I only B. II only C. III only D. I and III E. II and III 5. With a poorly chosen hash function, it is possible to have a situation in which the search time in a hash table of N items goes to A. O(N) B. O(N!) C. O(log N) D. O(N 2 ) E. O(1) David G. Sullivan, Ph.D. page 3 of 14

6. Nodes for a doubly linked list are defined to have the following structure: data next prev The next instance variable stores a reference to the next node in the list, and the prev instance variable refers to the previous node in the list. Below is a list of three of these nodes, along with two reference variables, n and p, that refer to specific nodes in the list. n p Which of the following expressions does not refer to the third node in the list? A. p.next B. n.next.next C. p.prev.next D. p.next.prev.next E. n.next.next.prev.next 7. A police department wants to maintain a database of up to 1800 license-plate numbers of people who receive frequent tickets so that it can be determined very quickly whether or not a given license plate is in the database. Speed of response is very important; efficient use of memory is also important, but not as important as speed of response. Which of the following data structures would be most appropriate for this task? A. a sorted linked list B. a sorted array with 1800 entries C. a hash table using open addressing with 1800 entries D. a hash table using open addressing with 3600 entries E. a hash table using open addressing with 10000 entries David G. Sullivan, Ph.D. page 4 of 14

8. A Huffman tree is constructed for a text document containing 5 characters. The character e appears most frequently, and the character i has the next highest frequency. Which of the following could be the Huffman tree for this document? I. II. e i e t o s t o s i III. s o t i e A. I only B. II only C. III only D. either II or III E. none of these 9. An array of 7 integers is being sorted by the heapsort algorithm. After the initial phase of the algorithm (constructing the heap), which of the following is a possible ordering for the array? A. 85 78 45 51 53 47 49 B. 85 49 78 45 47 51 53 C. 85 78 49 45 47 51 53 D. 45 85 78 53 51 49 47 E. 85 51 78 53 49 47 45 David G. Sullivan, Ph.D. page 5 of 14

10. The binary search tree shown below was constructed by inserting a sequence of items into an empty tree. 5 3 9 4 7 12 6 8 20 Which of the following input sequences will not produce this binary search tree? A. 5 3 4 9 12 7 8 6 20 B. 5 9 3 7 6 8 4 12 20 C. 5 9 7 8 6 12 20 3 4 D. 5 9 7 3 8 12 6 4 20 E. 5 9 3 6 7 8 4 12 20 David G. Sullivan, Ph.D. page 6 of 14

PART II: Answer three of the four questions in the space provided. You are welcome to try all four problems, but make sure to clearly indicate which three problems you want us to grade by circling the numbers of the problems. II-1. Trees (15 points total) a. 7 points Suppose the keys on the middle row of a standard keyboard (ASDFGHJKL) are inserted in succession into an initially empty binary search tree. Draw the tree after this sequence of insertions has been made. b. 8 points Suppose the keys on the middle row of a standard keyboard (ASDFGHJKL) are inserted in succession into an initially empty 2-3 tree. Draw diagrams to illustrate the growth of the tree, showing the tree just before and just after all splits. David G. Sullivan, Ph.D. page 7 of 14

II-2. Hashing (15 points total; 5 points each part) You are given an empty hash table of size 7 that uses open addressing. The following sequence of keys is to be inserted: 15 17 8 23 3 5 Insert these keys using each of the following approaches. If overflow occurs, say so, and indicate the element that causes the overflow. a. h(x) = x % 7; linear probing b. h(x) = x % 7; quadratic probing 0 1 2 3 4 5 6 0 1 2 3 4 5 6 c. h(x) = x % 7; double hashing with h2(x) = x / 7 + 1 (using integer division) 0 1 2 3 4 5 6 David G. Sullivan, Ph.D. page 8 of 14

II-3. Graph Algorithms I (15 points total) A 13 5 B C 10 17 20 18 30 22 D E F a. 4 points Perform a depth-first traversal of the graph shown above, starting with vertex C. Select the smallest edge first when appropriate. In the space below, list the vertices in the order in which they are visited. b. 4 points Perform a breadth-first traversal of the graph shown above, starting with vertex C. Select the smallest edge first when appropriate. In the space below, list the vertices in the order in which they are visited. c. 7 points Suppose you are using Dijkstra s algorithm to find the shortest path from vertex D to vertex E. List, in the order in which they become known, all vertices to which a shortest path is determined in the process of solving this problem, and the length of the shortest path to each of these vertices. David G. Sullivan, Ph.D. page 9 of 14

II-4. Graph Algorithms II (15 points total) A 13 5 B C 10 17 20 18 30 22 D E F a. 6 points Suppose that Prim s algorithm has been executed, starting from node F, up to the point at which there are four edges selected for inclusion in the minimal spanning tree. List these four edges in the order that they are selected for inclusion, using notation similar to (A, B) to specify an edge. b. 6 points Suppose that the MST2 algorithm from Problem Set 5 has been executed, up to the point where there are four edges selected for inclusion in the minimal spanning tree. List these four edges in the order that they are selected for inclusion. c. 3 points Show an example of a spanning tree that is not minimal by darkening the appropriate edges on the diagram below: A 13 B 5 C 10 17 20 18 30 22 D E F David G. Sullivan, Ph.D. page 10 of 14

PART III (25 pts total): Complete all of the following problems. This part of the exam deals with binary trees that are constructed of nodes that are instances of the following class: public class Node { public int key; public Object data; public Node left; public Node right; } a. 10 points The following Java method uses recursion to search for a key in the binary search tree whose root node is referred to by the parameter root. If it finds the key, it returns a reference to the corresponding data item. If it doesn t find it, it returns null. public static Object search(node root, int key) { if (root == null) return null; else if (key == root.key) return root.data; else if (key < root.key) return searchtree(root.left, key); else return searchtree(root.right, key); } In the space below, rewrite the search() method so that it uses iteration instead of recursion: David G. Sullivan, Ph.D. page 11 of 14

b. 10 points Write a Java method named mirror() that takes a reference to the root node of a binary tree and creates a new tree (with its own nodes) that is the mirror image of the original tree. For example: if root is a reference to the root of the tree on the left below, then the return value of mirror(root) would be a reference to the root of the tree on the right below. Hint: This method is much easier to write if you use recursion. 1 1 / \ 2 3 / \ 3 2 / \ / \ 4 5 5 4 / \ 6 7 / \ 7 6 public static Node mirror(node root) { } c. 5 points What is the running time of your implementation of the mirror() method? Use big-o notation, and explain your answer briefly. THE PRACTICE EXAM ENDS HERE. David G. Sullivan, Ph.D. page 12 of 14

Supplemental Practice Problems 1. Suppose that you need to maintain a collection of data whose contents are fixed i.e., you need to search for and retrieve existing items, but never need to add or delete items. Although the collection of data may be quite large, you may assume that it can fit in the computer s memory. Which of the following data structures is the most efficient one to use for this task? A. a sorted array B. a linked list C. a binary search tree D. a queue E. all of the above perform the same in this case 2. Given the array of integers arr shown below 5 19 6 12 48 6 23 39 2 18 what is the output of the following statements? int[] a2 = arr; a2[3] = arr[2]; arr[2] = arr[3]; arr[3] = a2[3]; System.out.println(arr[2] + + arr[3]); A. 6 12 B. 12 6 C. 6 6 D. 12 12 E. none of the above 3. If a binary search tree is not allowed to have duplicates, there is more than one way to delete a node in the tree when that node has two children. One way involves choosing a replacement node from the left subtree. If this is done, which node are we looking for? A. the largest node in the subtree B. the smallest node in the subtree C. the root of the left subtree D. the next-to-smallest node in the subtree E. it doesn t matter any node in the left subtree will do David G. Sullivan, Ph.D. page 13 of 14

4. Which of the following data structures is most appropriate for situations in which you need to efficiently manage (key, value) pairs that are stored on disk? A. an array B. a linked list C. a binary search tree D. a 2-3 tree E. a B-tree 5. Which of the following state-space search methods makes the most efficient use of memory? A. breadth-first search B. depth-first search C. greedy search D. A* search E. they are all equivalent 6. Consider the following recursive method: public static int recurse(int a, int b) { if (a % b == 2) return a; else return recurse(a + b, a - b); } What is returned by the call recurse(7, 2)? A. 5 B. 7 C. 9 D. 14 E. 18 7. Which of the following sorting algorithms does not require O(n 2 ) steps in the worst case? A. insertion sort B. selection sort C. heap sort D. bubble sort E. quicksort David G. Sullivan, Ph.D. page 14 of 14