Hashing · separate chaining

Chaining Lab

The hash table is an array of pointers, one per location. Each key is hashed to a location, and the chain there is searched. If the key is not already in the chain, a new node is linked onto the end. There is no bucket size, so a chain can grow as long as it needs to and nothing ever overflows.

Build the table

11
25/60
The hash function in C++

Compared with a perfectly random hash

If a hash spreads keys perfectly at random, each new key picks any of the m locations with chance 1/m. These charts compare this run with that ideal. A good hash stays close to the ideal; a poor hash on patterned keys does not.

How long are the chains?

Number of locations with each chain length, now.

this tableexpected for a random hash

Collisions as keys arrive

A collision is a new key whose location already has a chain.

this tableexpected for a random hash