Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume you have a HashMap class that uses a load factor of 0.75 (regardless of t

ID: 3567803 • Letter: A

Question

Assume you have a HashMap class that uses a load factor of 0.75 (regardless of the collision resolution mechanism used), and has an initial array size of 13. The table below contains a list of items, along with associated hashcodes that were computed using some hypothetical hash function. Assume the items are added to a newly created instance of the HashMap class in the same order in which they are listed in the table. Based on this information, answer the following questions:

Show what the array of the HashMap would look like after all the items below have been added, assuming the HashMap class uses separate chaining hashing to resolve collisions, and that the threshold is calculated based on the number of items present, not the number of array cells that contain at least one item. Assume the array is resized when the current item to be added will make the total number of items greater than or equal to the threshold value.

Show what the array of the HashMap would look like after all the items below have been added, assuming the HashMap class uses quadratic probing to resolve collisions instead of separate chaining hashing. Assume the array is resized when the current item to be added will make the total number of items greater than or equal to the threshold value.

Note that for both questions, you do not need to compute the hashcodes, you only need to determine where the items would be placed into the underlying array of the HashMap.

Item Hashcode Patriots 1342415383 Steelers 700056533 Chargers 330628742 Texans 532139483 Packers 217142585 49ers 2112979549 Saints 207265348 Giants 1631149803

Explanation / Answer

HashMap factor = 0.75 initial size = 13

When all 8 items are added, the load factor will be 8/13 < 0.75
so the hashtable will not be resized.

1. Show what the array of the HashMap would look like after
all the items below have been added. separate chaining

[0]:
[1]:
[2]: Chargers
[3]:
[4]: Saints
[5]: Texans -> 49ers
[6]:
[7]: Steelers
[8]:
[9]:
[10]: Patriots -> Packers -> Giants
[11]:
[12]:


2. Show what the array of the HashMap would look like after
all the items below have been added. uses quadratic probing

[0]:
[1]: Giants
[2]: Chargers
[3]:
[4]: Saints
[5]: Texans
[6]: 49ers
[7]: Steelers
[8]:
[9]:
[10]: Patriots
[11]: Packers
[12]:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote