Java Simulate the behavior of a hash map. Assume the following: the hash table array has an initial capacity of 10 the hash table uses separate chaining to resolve collisions and adds new values at the beginning of the linked list. 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 . Put a \ in the box 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. 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:____
Java
Simulate the behavior of a hash map. Assume the following:
- the hash table array has an initial capacity of 10
- the hash table uses separate chaining to resolve collisions and adds new values at the beginning of the linked list.
- 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 . Put a \ in the box 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.
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:____
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images