Also known as division remainder, the modulo-division method divides the key by array size (table size) and uses the remainder for the address. This method gives us the simple hashing algorithm shown below where tableSize is the number of elements in the array.
address = key MODULUS tableSize
As the little company begins to grow, we realize that soon we will have more than 100 employees. Planning for the future, we create a new employee numbering system that will handle 1,000,000 employees. We also decide that we want to provide data space for up to 300 employees. The first prime number greater than 300 is 307. We therefore choose 307 as out list (array) size, which gives us a table with addresses that range from 0 through 306. Our new employee table and some of its hashed addresses are shown in Figure 6.
121267/307 = 395 with remainder of 2
Therefore: hash(121267) = 2
In few books its given we have to add remainder +1 i.e 2+1 =3 as address
ReplyDeletecheck this out ajith
Deletehttp://note-for-it.blogspot.in/2008/11/algorithms-data-structures-hashing.html
This comment has been removed by the author.
DeleteTo reach at the exact location of array +1 is added
DeleteThanks a lot. Really helpful :)
ReplyDeleteThanks a lot. Really helpful :)
ReplyDeleteyou rock
ReplyDelete