Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Hash Tables: Understanding Hash Functions, Collisions, and Probing Techniques, Lecture notes of Data Structures and Algorithms

An overview of hash tables, including hash functions, collision resolution techniques, and linear and quadratic probing. It covers the distribution of keys, efficient computation, and common techniques for handling collisions. Students can use this document as a study aid for understanding hash tables and related concepts.

Typology: Lecture notes

2021/2022

Uploaded on 09/27/2022

millionyoung
millionyoung 🇬🇧

4.5

(25)

242 documents

1 / 35

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Hash Tables
See 5.1-5.6 and 5.9 in the
Textbook
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Partial preview of the text

Download Hash Tables: Understanding Hash Functions, Collisions, and Probing Techniques and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Hash Tables

See 5.1-5.6 and 5.9 in the

Textbook

Hash Tables

• Hash Functions

• Collision Resolution Techniques

• Linear Probing

• Quadratic Probing

• Review Questions

Hash Function

• For integer keys that are uniformly distributed the

hash function can mod the key (%) the table size

• For strings a simple hash function adds the

character codes of the characters in the string and

mods by the table size. This is easy to implement

and works for small table sizes

• Figure 5.4 in the book shows a better hash function

for strings. If keys are long strings the function can

be modified to use only some of the characters in

the string (i.e. every other character)

Collisions

• Two keys have the same hash function

value

Linear Probing

(^0) Noether (^1) Euler (^2) Cantor 3 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege hash(key) h 0 (key) h 1 (key) … hi(key) = (hash(key) + f(i)) mod N Where N is the table size For linear probing f(i) = i

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6

(^1) Euler 2 3 4 5 6 7 8 9 10 11 (^12) Frege

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6

(^1) Euler 2 3 4 (^5) Hardy 6 7 8 9 10 11 (^12) Frege

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 (^0) Noether (^1) Euler (^2) Cantor 3 4 (^5) Hardy 6 7 8 9 10 11 (^12) Frege

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 (^0) Noether (^1) Euler (^2) Cantor 3 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 (^0) Noether (^1) Euler (^2) Cantor 3 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege Full Full Full Empty Empty Full Full Empty Empty Empty Empty Empty Full

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 Search for Pascal (0) (^0) Noether (^1) Euler (^2) Cantor 3 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege Full Full Full Empty Empty Full Full Empty Empty Empty Empty Empty Full

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 Search for Pascal (0) Insert Pascal Remove Euler Search for Pascal (^0) Noether 1 (^2) Cantor (^3) Pascal 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege Full Empty Full Full Empty Full Full Empty Empty Empty Empty Empty Full

Linear Probing Example

Key Hash Function Value Frege 12 Euler 1 Hardy 5 Noether 12 Cantor 0 Fermat 6 Search for Pascal (0) Insert Pascal Remove Euler Search for Pascal (^0) Noether 1 (^2) Cantor (^3) Pascal 4 (^5) Hardy (^6) Fermat 7 8 9 10 11 (^12) Frege Full Removed Full Full Empty Full Full Empty Empty Empty Empty Empty Full