91
Performance
What’s the load factor of this hash table?
If you said
1
/
3
, you’re right. Load factor measures how many empty slots
remain in your hash table.
Suppose you need to store the price of 100 produce items in your hash
table, and your hash table has 100 slots.
In the best case, each item will
get its own slot.
This hash table has a load factor of 1. What if your hash table has only
50 slots? Then it has a load factor of 2. There’s no way each item will
get
its own slot, because there aren’t enough slots! Having a load factor
greater than 1 means you have more items than slots in your array.
Once the load factor starts to grow, you need to add more slots to your
hash table.
This is called
resizing
. For example, suppose you have this
hash table that is getting pretty full.
You need to resize this hash table. First you create a new array that’s
bigger. The rule of thumb is to make an array that is twice the size.