Middle
On what principle does the number of buckets in a hash table increase?
sobes.tech AI
Answer from AI
The number of buckets in a hash table usually increases by doubling the size when a certain fill threshold, called the load factor, is reached. For example, in the standard Java HashMap implementation, the initial bucket size is 16, and when the fill level reaches about 75% (load factor = 0.75), the number of buckets is doubled (32, 64, etc.).
This is done to reduce the number of collisions and maintain the efficiency of insert and search operations. When the size increases, rehashing of elements into new buckets occurs.
Example:
HashMap<String, Integer> map = new HashMap<>();
// When adding elements, if the number of elements exceeds 0.75 * currentCapacity,
// the bucket size will automatically double.