Hashing
Hashing
Hashing
Concept of Hashing
Look-Up Table
Dictionary
Cache
Extended Array
Tables of logarithms
Example
. . .
. . .
. . .
b-1 . . .
Data Structure for Hash Table
#define MAX_CHAR 10
#define TABLE_SIZE 13
typedef struct {
char key[MAX_CHAR];
/* other fields */
} element;
element hash_table[TABLE_SIZE];
Other Extensions
• Insert pairs whose keys are 6, 12, 34, 29, 28, 11,
23, 7, 0, 33, 30, 45
Linear Probing – Delete
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
Delete(0)
0 4 8 12 16
34 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
34 45 6 23 7 28 12 29 11 30 33
Linear Probing – Delete(34)
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
0 45 6 23 7 28 12 29 11 30 33
Performance Of Linear Probing
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
Sorted Chains
[4]
• Put in pairs
whose keys are 6 23
6, 12, 34, 29, 7
28, 11, 23, 7, 0, [8]
33, 30, 45
• Bucket = key %
17. 11 28 45
[12] 12 29
30
[16] 33
Comparison : Load Factor
If open addressing is used, then each
table slot holds at most one element,
therefore, the loading factor can never
be greater than 1.