Consider a hash table of size 10, and the following items are to be stored. Item
are in the (key, value) format. Map the key values to the indexes of an array.
• (1,20)
• (2,70)
• (42,80)
• (4,25)
• (12,44)
• (14,32)
• (17,11)
• (13,78)
• (37,98)
Total number of records in the array = 10
var table=LinkedList[10]
/* insert new record(key, value) */
hash =key%10
table[hash].AddFirst(Key,value)
value=table[key%10].Find(key)
Steps to insert key value pair are given below-
{
int hash = 118
// {"20"} is not a string but
// an object of class Key
Key key = {"20"}
Integer value = 1
Node next = null
}
Array ={20, 70, 80, 25, 44,32, 11, 78,98}
Hash code are listed below in the image
But here we can see that many elements are getting the same hash code so,
Comments
Leave a comment