0
5.0kviews
What is hashing ? What is mean by collision? Using modulo division method insert the following values in a hash table of size 10. Show how many collisions occurred. 99, 33, 23, 44, 56, 43, 19
1 Answer
3
324views
  1. Hashing is a technique by which updating or retrieving any entry can be achieved in constant time O(1).
  2. In mathematics, a map is a relationship between two sets. A map M is a set of pairs, where each pair is in the form of (key, value).
  3. For a given key, its corresponding value can be found with the help of a function that maps keys to values. This function is known as the hash function.
  4. So, given a key k and a hash function h, we can compute the value/location of the value v by the formula v = h(k).
  5. Hash function is a division modulo operation, such as h(k)=k mod size, where size is the size of the data structure that holds the values.
  6. Collision is the event of two keys hashing to the same location.
  7. A collision can be dealt with by a. linear probing (looking at the next available location-i+1, i+2,…), b. quadratic probing (same as linear probing with quadratic spaces-i+1, i+4, i+9,…) and c. chaining (process of creating a linked list of values if they hash into the same location)
  8. The following is the solution to the given hashing problem:-

enter image description here

99 mod 10 is 9. Since it’s vacant, 99 gets stored at position 9.

33 mod 10 is 3. Since it’s vacant, 33 gets stored at position 3.

23 mod 10 is 3. Since 3 is already occupied by 33, 23 gets stored at the next available location, 4. (1 collision)

44 mod 10 is 4. Since 4 is already occupied by 23, 44 gets stored at the next available location, 5. (1 collision)

56 mod 10 is 6. Since it’s vacant, 56 gets stored at position 6.

43 mod 10 is 3. Since 3 is already occupied by 33, 43 gets stored at the next available location, 7. (4 collisions)

19 mod 10 is 9. Since it is already occupied by 99, 19 gets stored at the next available location, 0. (1 collision)

Please log in to add an answer.