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(3, 12);
map.put(4, 11);
map.put(77, 1);
map.put(7, 8);
map.put(5, 22);
map.put(17, 3);
map.put(19, 108);
map.put(47, 100);
map.put(44, 46);
map.put(11, 22);
map.put(2, 17);
map.put(1, 19);
map.put(11, 100);
map.put(9, 181);
map.remove(17);
map.remove(181);
if (map.containsKey(122)) {
map.put(1, 1);
} else {
map.put(28, 3);
}
int x = 1;
while (map.containsKey(3)) {
if (map.containsKey(x)) {
map.remove(x);
}
x++;
}
map.put(47, 100);