Simulate the behavior of a hash map as described and implemented in lecture. Assume the following:
-
the hash table array has an initial capacity of 10
-
the hash table uses separate chaining to resolve collisions
-
the hash function returns the absolute value of the integer key, mod the capacity of the hash table
-
rehashing occurs at the end of an add where the load factor is ≥ 0.75 and doubles the capacity of the hash table
Fill in the diagram to show the final state of the hash table after the following operations are performed.
Write each bucket as key:value pairs with arrows between them, such as key1:value1 -> key2:value2 -> key3:value3
.
Leave a box empty if an array element is unused.
Also write the size, capacity, and load factor of the final hash table.
Write the load factor in 0.x format, such as 0.5 or 0.75.
HashMap map;
map.put(55, 2);
map.put(75, 99);
map.put(99, 55);
map.put(75, -1);
map.put(15, 99);
map.put(39, 39);
map.remove(5);
map.remove(5);
map.put(0, 10);
map.put(2, 0);
int n = map.get(75);
n++;
map.put(72, 27);
map.remove(75);
map.remove(map.get(15));
map.put(89, 1);
map.put(59, 47);