Machine-translated by Google. Questions are authored in English.
Top

Discussion

While hashing 5 integer keys namely 5, 12, 23, 32, 104 using the hash function h(key) = key % 10 into a hash table with 10 buckets the number of keys that will collide is

  • A.0
  • B.1
  • C.2
  • D.3

Answer: C

The number of keys that collide is 2.

Apply h(key) = key % 10 to each key:

Key5122332104
Bucket52324

Only bucket 2 receives more than one key: 12 and 32 both end in 2. So 2 keys collide. Counting the collision as one event gives 1, the trap; 0 ignores the shared bucket and 3 counts a key that has a bucket to itself.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.