logo CodeStepByStep logo

hashMapOperations3

Language/Type: C++ inheritance polymorphism

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. Write the load factor in 0.x format, such as 0.5 or 0.75.

HashMap map;
map.put(8, 11);
map.put(26, 9);
map.put(16, 9);
map.put(26, 88);
map.put(196, 44);
map.put(38, 11);
map.put(32, 77);
map.remove(26);
map.remove(9);
map.put(100, 44);
if (map.containsKey(196)) {
    map.remove(44);
}
map.put(56, 56);
map.put(-48, 34);
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

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.