How do I properly calculate the load factor of a hash table that uses separate chaining?

18.1k views Asked by At

I'm working with hash tables that use separate chaining as a collision resolution technique.

I do know that the general formula is N/table_length, where N is the number of items currently in the table.

I'm a bit confused by the denominator. Would it be the size of the array + the number of chained elements, or simply the size of the array?

1

There are 1 answers

2
JaMiT On BEST ANSWER

The purpose of the load factor is to give an idea of how likely (on average) it is that you will need collision resolution if a new element is added to the table. A collision happens when a new element is assigned a bucket that already has an element. The chance that a given bucket already has an element depends on how many elements are in the container.

load factor = # of elements / # of buckets

(In your terminology: the number of items currently in the table divided by the size of the array.)