teach-ict.com logo

THE education site for computer science and ICT

2. Producing hashes

Hash tables are a type of array. What sets them apart is that, instead of storing raw data, hash tables store fixed-length 'hashes' of the data.

These hashes are created by applying a hash function to the data items. The algorithms behind hash functions can get very complicated, and you will rarely (if ever) need to know exactly how they work.

For this section, we'll use the following integers as the data set

{31407812, 10037467, 75203429, 52783465, 62387678}

We will use a Modulo 11 calculation as a simple hash function. This divides each number by 11 as many times as it will fit, then records the remainder.

NOTE: We are using Modulo 11 just to explain the concept. It is actually a very poor hash function because it effectively assigns all sequences to only 11 values - too much duplication. A good hash function such as the commonly used md5 algorithm has far fewer duplicated hashes.

Running the hash function on the data set produces the following set of hashes

{7, 0, 4, 9, 1}

 

hash system

 

The next step is to store the data in the hash table.

 

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is a hash function