Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 349
Adam G Avatar asked Nov 18 '25 02:11

Adam G


1 Answers

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.)

like image 74
JaMiT Avatar answered Nov 20 '25 16:11

JaMiT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!