## hashMapOperations6

Language/Type: C++ inheritance polymorphism
Author: Marty Stepp (on 2016/06/16)

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.5 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.

```HashMap map;
map.put(8, 8);
map.put(26, 62);
map.put(16, 62);
map.put(26, 999);
map.put(196, 44);
map.put(38, 83);
map.put(51, 15);
map.remove(62);
map.remove(16);
map.put(100, 0);
if (map.containsKey(196)) {
map.remove(44);
}
map.put(66, 66);
map.put(-48, 74);```
 `hashTable[0]` `hashTable[1]` `hashTable[2]` `hashTable[3]` `hashTable[4]` `hashTable[5]` `hashTable[6]` `hashTable[7]` `hashTable[8]` `hashTable[9]` `hashTable[10]` `hashTable[11]` `hashTable[12]` `hashTable[13]` `hashTable[14]` `hashTable[15]` `hashTable[16]` `hashTable[17]` `hashTable[18]` `hashTable[19]` `size` `capacity` `load factor`

Need help?

If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.