Upload
nifras-ismail
View
303
Download
1
Embed Size (px)
Citation preview
Separate chaining has the disadvantage of using linked lists.
Requires the implementation of a second data structure.
In an open addressing hashing system, all the data go inside the table.
Thus, a bigger table is needed.Generally the load factor should be below 0.5.
If a collision occurs, alternative cells are tried until an empty cell is found.
0
1
2
3
4
5
6
7
8
9
h(k) = k mod mm = 10
h(10) = 10 mod 10 = 0h(20) = 20 mod 10 = 0h(30) = 30 mod 10 = 0h(40) = 40 mod 10 = 0h(50) = 50 mod 10 = 0
0
1
2
3
4
5
6
7
8
9
10 ←-- 20 ←- 30 ←-- 40 ←-- 50
All the nodes are on the chain of
linked listTake extra space for
linked list but
not use available space in hash table
0 10
1
2
3
4
5
6
7
8
9
h(20) = 20 mod 10 = 0
But there is a collision so we search the next free space
In linear probing, collisions are resolved by sequentially
scanning an array (with wraparound) until an empty cell is
found.i.e. f is a linear function of i, typically f(i)= i
But we have an issue on this Linear Probing is clustering
As long as table is big enough, a free cell can always
be found, but the time to do so can get quite large.
Summary We have solve the issue of extra memory and utilize the avaliable
memory in the hash table Insertion take more time on to find the free space Finding the element also following the insertion algorithm, so it
also take too time Deletion cannot be done in a single shot
In Linear Probing
h(x)i = Hash(x) + f(i) Where f(i) = i
In Quadratic Probing
h(x)i = Hash(x) + f(i) Where f(i) = i2
A second hash function is used to drive the collision resolution.
h(x)i = Hash(x) + f(i) f(i) = i * hash2(x)
This is the second hash function
Some Hashing ApplicationsCompilers use hash tables to implement the symbol table
Game programs use hash tables to keep track of positions it has encountered
On line spelling checkers