Question

In: Computer Science

Consider inserting n distinct keys into a hash table with m buckets, where collisions are resolved...

Consider inserting n distinct keys into a hash table with m buckets, where collisions are resolved by chaining and simple uniform hashing applies.

1. What is the probability that none of the n keys hashed to a particular bucket?

2. What is the expected number of empty buckets?

3. What is the expected number of collisions?

Solutions

Expert Solution

1.

Let's take the bucket 1 to be empaty means note a single key inserted in that bucket. If bucket 1 is empty after n insertions that means keys must have mapped to remaining m-1 locations, n insertions means n keys mapped.

So the probability that none of the keys hashed to bucket 1 = (1 - 1 / m)n

same applies for all the buckets, so the probability that none of the n keys hashed to a particular bucket is

= (1 - 1 / m)n

2.

The probability that a bucket remains empty after mapping all n keys is (1 − 1 / m )n. Defining

X = { 1 if bucket remains empty; 0 otherwise }

thus E(X) = (1 − 1 / m )n.

The number of empty buckets is X = X1 + X2 + . . . + Xm.

Hence, the expected number of empty buckets is

sum(X) = m (1 - 1 / m)n

3.

The number of collisions can be determined from the number of empty buckets.

Writing X for the number of empty buckets, as above,

we have m − X items hashed without collision and therefore a total of n − m + X collisions.

Writing Z for the number of collisions,

thus E(Z) = n − m + E(X)

= n − m + m (1 − 1 / m )n  

For m = n, we get limn→∞ n(1 − 1 / n )n = n / e

in other words the third of the keys is expected to cause collisions.


Related Solutions

1.) Consider inserting values 15, 22 and 29 in the order given into a hash table...
1.) Consider inserting values 15, 22 and 29 in the order given into a hash table of size 7 with hash function h(x) = x mod 7. What will be the locations be the respective locations for 15, 22 and 29 in the hash table if quadratic probing is used to resolve colisions? a. 1, 2, 4 b. 1, 2, 3 c. 1, 2, 0 d. 1, 1, 1 2.) Consider the following sequences of addqs and removeqs, what order...
Consider inserting values 15, 22 and 29 in the order given intoa hash table of...
Consider inserting values 15, 22 and 29 in the order given into a hash table of size 7 with hash function h(x) = x mod 7. What will be the locations be the respective locations for 15, 22 and 29 in the hash table if quadratic probing is used to resolve colisions?a.1, 2, 4b.1, 2, 3c.1, 2, 0d.1, 1, 1
Consider a hash table T with m=10 slots that uses open addressing with linear probing and...
Consider a hash table T with m=10 slots that uses open addressing with linear probing and the hash function h(k,i) = ((k mod m) + i) mod m, where i = 0,1,..., m-1 is the probe number. Show T after inserting keys <867,755,535,296,866,135,669,445,524>.
A hash table works as follows. We allocate a table of m slots. All the items...
A hash table works as follows. We allocate a table of m slots. All the items we intend to store in the table belong to a large set U of items. We adopt a function f: U ->{0,1...m-1) which maps an item to a slot. Suppose we seek to store n items from U in a table of m slots. (a) Suppose f maps every item in U with equal probability to one of the m slots. What is the...
(i) T(n) denote the number of distinct ways that a postage of n cents, where n...
(i) T(n) denote the number of distinct ways that a postage of n cents, where n ≥ 4 and n is even, can be made by 4-cent and 6-cent stamps. Find a recurrence relation T(n). NOTE [4,6] is the same as [6,4] so T(10) = 1 so T(n) is NOT T(n-4)+T(n-6) (ii) Now assume we have 10-cent stamps in addition to the previous 2 kinds. Find a recurrence relation, S(n), for the number of distinct ways that a postage of...
(i) T(n) denote the number of distinct ways that a postage of n cents, where n...
(i) T(n) denote the number of distinct ways that a postage of n cents, where n ≥ 4 and n is even, can be made by 4-cent and 6-cent stamps. Give a recursive algorithm (written in Python) to compute T(n) for n ≥ 4 and n is even. Briefly explain why the algorithm is correct but no formal proof is required. NOTE [4,6] is the same as [6,4] so T(10) = 1. (ii) Now assume we have 10-cent stamps in...
[Algorithm Question] Consider inserting the keys 12, 28, 31, 7, 15, 17, 66, 59, 21, 3,...
[Algorithm Question] Consider inserting the keys 12, 28, 31, 7, 15, 17, 66, 59, 21, 3, 1 into a hash table of length m = 5 using seperate chaining where h(k) = k mod m. Illustrate the result of inserting these keys.
Consider an undirected graph G that has n distinct vertices. Assume n≥3. How many distinct edges...
Consider an undirected graph G that has n distinct vertices. Assume n≥3. How many distinct edges will there be in any circuit for G that contains all the vertices in G? What is the maximum degree that any vertex in G can have? What is the maximum number of distinct edges G can have? What is the maximum number of distinct edges that G can have if G is disconnected?
Assume that you are hashing key K to a hash table of n slots (indexed from...
Assume that you are hashing key K to a hash table of n slots (indexed from 0 to n - 1). For each of the following functions h(K), answer the following question(s): 1) Is the function acceptable as a hash function (i.e., would the has program work correctly for both insertions and searches), 2) and if so, is it a good hash function? Function rand(n) returns a random integer between 0 and n - 1. Also assume k is a...
Consider the m by n grid graph: n vertices in each of m rows, and m...
Consider the m by n grid graph: n vertices in each of m rows, and m vertices in each of n columns arranged as a grid, and edges between neighboring vertices on rows and columns (excluding the wrap-around edges in the toric mesh). There are m n vertices in total. a)What is the diameter of this graph? b) From the top left vertex to the bottom right vertex, how many shortest paths are there? Please explain.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT