Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5?
Question
Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5?
Solution
To answer this question, we need to understand the concept of the Birthday Paradox, which is a probability theory. It states that the probability of at least two people sharing a birthday is more than 50% even in a small group of 23 people. This is because the number of possible pairs is not linear, but quadratic.
In the context of a hash table, the Birthday Paradox applies to hash collisions. A hash collision occurs when two different keys hash to the same index in an array.
Here's how we can calculate it:
-
The hash table size is 20, so there are 20 different "slots" a key can hash to.
-
When the first key is hashed, there are no existing keys, so the probability of collision is 0.
-
When the second key is hashed, there is 1 existing key, so the probability of collision is 1/20.
-
For the third key, the probability of collision is 2/20, and so on.
-
We want to find out after how many keys the probability of collision exceeds 0.5. This means we need to solve for n in the equation n/20 > 0.5.
Solving for n gives us n > 10. However, since we can't hash a fraction of a key, we round up to the nearest whole number.
So, after hashing 11 keys, the probability that any new key hashed collides with an existing one will exceed 0.5.
Similar Questions
Multi Choice Type QuestionConsider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5?Note: This question was asked in Gate CS Exam.Marks : 1Negative Marks : 0Answer here56710
What is the probability of a collision when hashing n keys into a hash table of size m, assuming that the hash function produces a uniform random distribution?
Consider a hash table with 11 slots. The hash functionis h(k) = k mod 11. The collisions are resolved byopen Hashing(Chaining). The following 11 keys are inserted in theorder: 28, 19, 15, 20, 33, 30, 42, 63, 60, 32, 43. Themaximum, minimum, and average chain lengths in thehash table, respectively, are-
Collisions can be completely avoided in a hash table by choosing a perfect hash function. Group of answer choicesTrueFalse
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and the hash function used is key % 10. If the values 43, 165, 62, 123, 142 are inserted in the table, in what location would the key value 142 be inserted?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.