Question

In: Computer Science

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>.

Solutions

Expert Solution

Solution:

Given,

=>Hash table size(m) = 10

=>Linear probing is used for collision resolution

=>Hash function: h(k) = (kmodm + i) mod m where i = 0, 1 ....m-1

=>Keys = 867, 755, 535, 296, 866, 135, 669, 445, 524

Explanation:

Inerting keys:

Insert 487:

=>487 mod 10 = 7

Insert 755:

=>755 mod 10 = 5

Insert 535:

=>535 mod 10 = 5(collision)

=>(5 + 1) mod 10 = 6

Insert 296:

=>296 mod 10 = 6(collision)

=>(6 + 1) mod 10 = 7(collision)

=>(6 + 2) mod 10 = 8

Insert 866:

=>866 mod 10 = 6(collision)

=>(6 + 1) mod 10 = 7(collision)

=>(6 + 2) mod 10 = 8(collision)

=>(6 + 3) mod 10 = 9

Insert 135:

=>135 mod 10 = 5(collision)

=>(5 + 1) mod 10 = 6(collision)

=>(6 + 1) mod 10 = 7(collision)

=>(6 + 2) mod 10 = 8(collision)

=>(6 + 3) mod 10 = 9(collision)

=>(6 + 4) mod 10 = 0

Insert 669:

=>669 mod 10 = 9(collision)

=>(9 + 1) mod 10 = 0(collision)

=>(9 + 2) mod 10 = 1

Insert 445:

=>445 mod 10 = 5(collision)

=>(5 + 1) mod 10 = 6(collision)

=>(6 + 1) mod 10 = 7(collision)

=>(6 + 2) mod 10 = 8(collision)

=>(6 + 3) mod 10 = 9(collision)

=>(6 + 4) mod 10 = 0(collision)

=>(6 + 5) mod 10 = 1(collision)

=>(6 + 6) mod 10 = 2

Insert 524:

=>524 mod 10 = 4

Final hash table:

135 669 445 524 755 535 487 296 866

    0           1           2        3     4          5             6         7           8              9

I have explained each and every part with the help of statements attached to the answer above.


Related Solutions

Write an algorithm to delete an element from a hash table that uses linear probing as...
Write an algorithm to delete an element from a hash table that uses linear probing as its clash resolution strategy. Analyze your algorithm and show the results using order notation?
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...
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 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?
Consider the linear transformation T: R2x2 -> R2x2 defined by T(A) = AT - A. Determine...
Consider the linear transformation T: R2x2 -> R2x2 defined by T(A) = AT - A. Determine the eigenvalues of this linear transformation and their algebraic and geometric multiplicities.
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
. Let T : R n → R m be a linear transformation and A the...
. Let T : R n → R m be a linear transformation and A the standard matrix of T. (a) Let BN = {~v1, . . . , ~vr} be a basis for ker(T) (i.e. Null(A)). We extend BN to a basis for R n and denote it by B = {~v1, . . . , ~vr, ~ur+1, . . . , ~un}. Show the set BR = {T( r~u +1), . . . , T( ~un)} is a...
1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25...
1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25 keys. Do you expect to see any collisions? Why or why not? Yes, because random values likely will land on same locations. No becase there are four times as many slots as needed. 2. Secondary clustering means that elements that hash to the same position will probe to the same alternate cells. Simple hashing uses key%tablesize as the hash function. Which of the following...
void phase05(){ int n = atoi(next_input()); int m = atoi(next_input()); int t = (hash % 30)...
void phase05(){ int n = atoi(next_input()); int m = atoi(next_input()); int t = (hash % 30) + 21; int s = 0; while(n>1){ if(n & 1){ n = (n<<2) - n + 1; } else { n = n >> 1; } if(s == t && m == t){ return; } s++; } failure("Seems you forgatz the essence of Collatz"); } Hash value: 2002296385 what input values should n, m have in order for the function phase05 to work?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT