Question

#3 [3 points]

Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and quadratic probing is used to resolve collisions, after the following elements are inserted:

20, 42, 45, 49, 62, 72, 95.

The probes are based on this equation: (H+c1∗i+c2∗i2)mod(N) and c1=1, c2=1.

0 1 23 4 5 6 78 9 10

If direct hashing was used to store the same elements as the previous problems (20, 42, 45, 49, 62, 72, 95), what should be the minimum size of the hash table?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
42 45 95 49 72 62 20

0 1 2 3 4 5 6 7 8 9 10

Size of the table = 11

Hash function : Key mod N

In case of collision Quadratic Probing is used

Formula for quadratic probing

(H+c_{1}\times i\,+\,c_{2}\times i^{2})\,\,\mathbf{mod}\,N

Sequence of keys given

20, 42, 45, 49, 62, 72, 95

H(20) = 20 mod 11 = 9

So 20 is placed at index 9 in the hash table

H(42) = 42 mod 11 = 9

But there is already a key at position 9, so there is a collision

To resolve collision, we use Quadratic probing

(H + c1∗i + c2∗i2 )mod (N)

(9 + 1*1 + 1*1) mod 11 = 11 mod 11 = 0

So 42 is placed at index 0 in the hash table

H(45) = 45 mod 11 = 1

So 45 is placed at index 1 in the hash table

H(49) = 49 mod 11 = 5

So 49 is placed at index 5 in the hash table

H(62) = 62 mod 11 = 7

So 62 is placed at index 7 in the hash table

H(72) = 72 mod 11 = 6

So 72 is placed at index 6 in the hash table

H(95) = 95 mod 11 = 7

But there is already a key at position 7, so there is a collision

To resolve collision, we use Quadratic probing

(H + c1∗i + c2∗i2 )mod (N)

(7 + 1*1 + 1*1) mod 11 = 9 mod 11 = 9

But there is collision at index 9 because 20 is present there

(7 + 1*2 + 1*4) mod 11 = 13 mod 11 = 2

So 95 is placed at index 2 in the hash table

If direct hashing was used, every key would have its place fixed in the hashing table. Every key is placed at the position equal to its key value

So following will be the hashing

H(20) = 20

H(42) = 42

H(45) = 45

H(49) = 49

H(62) = 62

H(72) = 72

H(95) = 95

Thus the minimum table size will be 96 (including index 0)

Add a comment
Know the answer?
Add Answer to:
#3 [3 points] Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and quadratic probing is used to resolve collisions, after the following elements are inserted: 20, 42,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • It should be really short and simple to do this. #1 [8 points) Sketch a hash...

    It should be really short and simple to do this. #1 [8 points) Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and chaining is used to resolve collisions, when the following elements are inserted: 20, 42, 45, 49, 62, 72,95 0 1 2 3 4 5 6 7 8 9 10 What is the size of the largest bucket? — #2 [7 points) Sketch a hash table of size N=11, where...

  • 5. Hashing (a) Consider a hash table with separate chaining of size M = 5 and...

    5. Hashing (a) Consider a hash table with separate chaining of size M = 5 and the hash function h(x) = x mod 5. i. (1) Pick 8 random numbers in the range of 10 to 99 and write the numbers in the picked sequence. Marks will only be given for proper random numbers (e.g., 11, 12, 13, 14 ... or 10, 20, 30, 40, .. are not acceptable random sequences). ii. (2) Draw a sketch of the hash table...

  • 13) consider the following sequence of keys to be inserted in a hash table of size...

    13) consider the following sequence of keys to be inserted in a hash table of size 13 that uses a quadratic probing to resolve collisions select the choice that indicateds what the hash table looks like after all the keys are inserted (0 indicates an empty slot) {23, 4, 78 , 17 , 30, 81, 41, 5} a) 78, 41, 0, 81, 4, 5, 17, 0, 30, 0, 23, 0, 0 b) 78, 17, 41, 81, 4, 5, 0, 30,...

  • ZOOM Page 7. Apply the following operations on the following Quadratic probing haslh table. Write down all your calculations and changes to the hash table Hashi (key): key % 16 Hash2(key): 11-key % 1...

    ZOOM Page 7. Apply the following operations on the following Quadratic probing haslh table. Write down all your calculations and changes to the hash table Hashi (key): key % 16 Hash2(key): 11-key % 11 Double hashing probing sequence (Hashi (key) + i * Hash2(key)) % 16 149 3 88 a. (5 points)HashInsert(Table, 17) 6 16 7 23 8 24 10 42 12 99 13 14 15 b. (5 points)Hashremove(Table,16) ZOOM Page 7. Apply the following operations on the following Quadratic...

  • Type up and get the Hash table on pages 19 - 22 to work. Show your...

    Type up and get the Hash table on pages 19 - 22 to work. Show your sample test run at the bottom of your code using a multiline comment I typed everything but the code is not working please help me fix the mistakes. These are pages 19-22. The code I have: #include <iostream> #inlcude <iomanip> #include <stack> #include <vector> #include <cstdlib> #include <ctime> using namespace std; //////////////////////////////HASH TABLE/////////////////////////////////////////////// //hash.cpp //demonstrate hash table with linear probing /////////////////////////////////////////////////////////////////////////////////////// class DataItem {...

  • Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a =...

    Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT