Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

Hash Tables

Connect

• State three uses for hashing data


File Storage
• If we want to store a range of files online we can use a hash to create a
unique value for that file.

• We can then use that value to create an index location in a database or


an array.

• This is known as a hash table.


Hash Table
• The hash table therefore stores the location of files

• However, what if the hash creates a collision?

• Another position needs to found in the table for the


data, this called re hashing
Open Addressing
• When a hash collision occurs the data cannot be stored in the same
position as one that is already occupied.
• When this happens open addressing will start at the calculated index
position and search for the next “open” address i.e. the next index
position which is empty.
• The data is then stored at this position.
• In this example Sandra Dee is stored in index
position 03
Open Addressing….
• When a search is performed for that piece of data
the hash function will go to the original index
position.
• From this position a linear search is performed to
find the required data, known as linear probing.
• If another file returns a hash value that has been
taken by up linear probing, the same process is
applied i.e. the next available index location is
used.
• In this example a name which returned a hash
value of 03 would be stored in location 05
Chaining
• Chaining involves the use of a 2D array.
• This allows more than one piece of data to share the same index
location position on one axis but a different location index on the
other.
Overflow tables
• A separate table is created to store the other values with come up with
the same index position.
• The data is then searched for sequentially within the overflow table
until it is found
Linked Lists
• A linked list makes use of multiple lists which are “linked” together.
• Each “node”/index position contains a piece of data and a pointer
(location) of the next data item with the same hash value.
• Again, the links are searched sequentially until the required data is
found
• 91. OCR A Level (H446) SLR14 - 1.4 Data structures part 5 - Hash tab
les (youtube.com)
Storing Passwords

• Each password is hashed and indexed. 1.123456


• However…. 2.123456789
• Many people may choose the same password…. 3.qwerty
4.password
• 10 most common passwords in 2024….
5.12345
6.qwerty123
• This can result is multiple data collisions… 7.1q2w3e
8.12345678
9.111111
10.1234567890
• How NOT to Store Passwords! - Computerphile (youtube.com)

You might also like