






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
A java exam focused on hashmaps and hashing. It includes instructions, 11 questions, and a table for recording answers. Students are required to answer questions related to modifying keys and values in hashmaps, implementing the getresidents method for an addressbook class, and analyzing the behavior of a binary search tree's pathspreorder method.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







You have 110 minutes to finish this test. Your exam should contain 7 problems (numbered 0-6). This is an open-book test. You may consult any books, notes, or other paper-based inanimate objects available to you. Read the problems carefully. If you find it hard to understand a problem, please ask a question. Please write your answers in the spaces provided in the test; if you need to use the back of a page make sure to clearly tell us so on the front of the page.
Good Luck!
Question 1: (3 points)
When you modify a key that has been inserted into a HashMap will you be able to retrieve that entry again? Always Sometimes Never Explain:
When you modify a value that has been inserted into a HashMap will you be able to retrieve that entry again? Always Sometimes Never Explain:
Question 3 (8 points):
You are provided the classes Person, Address and AddressBook in the handout. In the space on this and the next page, add code to any of the three classes or provide new versions of existing methods as necessary to implement the getResidents method for AddressBook. getResidents should return an ArrayList of Person objects that are associated with a given address. The getResidents method takes a single argument of an Address and must run in constant time. There are no restrictions on the time complexity of any other methods. java.util methods are outlined in the attached handout.
Please make it very clear in which class each method would appear.
Question 4 continued:
b) Provide the body of the static method find, which will be called by the non-static find method shown in the handout. Your code should return the Bacteria object with the name tryingToFind if it is reachable from the node current, or return null if it cannot be found. You may only provide code for the static method find and may not change any other code.
private static Bacteria find(String tryingToFind, Bacteria current) {
Question 5: (5 points)
In the handout we have an abbreviated Binary Search Tree class called BST. The traditional insert and remove methods have been omitted for brevity. The insert method ignores attempts to insert elements already in the tree. The remove method will remove the inorder successor when necessary.
We added an instance variable to each node called pathFromRoot. We implement a method paths that stores for each node, a path from the root of L’s and R’s. The table above gives the value of pathFromRoot for each node in the tree on the right.
a) Assuming that insert is defined correctly for the BST class, after calling insert, would any node have a pathFromRoot that is not accurate? Yes No If yes, please explain which nodes will have an inaccurate value for pathFromRoot and under what conditions. If no, please explain why not.
b) Assuming that remove is defined correctly for the BST class, after calling remove, would any node have a pathFromRoot that is not accurate? Yes No If yes, please explain which nodes will have an inaccurate value for pathFromRoot and under what conditions. If no, please explain why not.
Question 6 Continued
b) Write the non-static helper method reduceHelper for the IntListNode class. The method reduceHelper, is called by reduce in the IntList class. You may only write code in the reduceHelper method and may not change or add other methods.
private IntListNode reduceHelper() {
Page intentionally left blank.
You may use it for extra space. If you expect it to be graded you must indicate so clearly on the relevant problem.