








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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, ...
Typology: Exams
1 / 14
This page cannot be seen from the preview
Don't miss anything!
name ____________________________________________
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 a single 8.5-inch x 11-inch sheet of notes (handwritten on both sides). Please turn off and put away all other materials (including phones and watches). Do all your work on the exam itself. Keep everything stapled together. 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
Answers to Part I:
question #: 1 2 3 4 5 6 7 8 9 10 answer:
Important: Put an X through the empty SCORE box of the problem from Part II that you do not want us to grade.
Write your answers in the table at the bottom of the cover sheet.
A. item A B. item B C. item C D. item D E. item E
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.
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.
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
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
next prev
data
A. I only B. II only C. III only D. either II or III E. none of these
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
e i
t
o s
e
t o s i
s o t
i e
Note: There may not be an option to choose among problems on the actual final exam.
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.
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
c. h(x) = x % 7; double hashing with h2(x) = x / 7 + 1 (using integer division)
0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6
II-4. Graph Algorithms II (15 points total)
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
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:
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
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
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
A. an array B. a linked list C. a binary search tree D. a 2-3 tree E. a B-tree
A. breadth-first search B. depth-first search C. greedy search D. A* search E. they are all equivalent
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
A. insertion sort B. selection sort C. heap sort D. bubble sort E. quicksort