Question

Consider the keys given below: 200   15   8   22   28   30   31 If we were to...

Consider the keys given below:

200   15   8   22   28   30   31

If we were to store the above keys into the hash table, which of the following three Hash Function is the best:

•   Function 1:    Key % 22
•   Function 2:    Key % 10
•   Function 3:    (Key – R) % R    where R is the greatest prime number less than the smallest key


Give solid reason to support your answer. A correct answer with an incorrect logic o will result in ZERO marks.

C++ code is NOT required for this question. Along with the answer, you should however explain how you came up with the answer to your question:

Homework Answers

Answer #1

The keys are given as

200 15 8 22 28 30 31

For hash Function 1: Key % 22 , the index valuse are calculated as

[ex:200 % 22 = 2]

2, 15, 8, 0, 6, 8, 9 which can be arrenged as 0, 2, 6, 8, 8, 9, 15

there is one collision.

For hash Function 2: Key % 10 , the index valuse are calculated as

0, 5, 8, 2, 8, 0, 1 clearly there are 2 collisions.

For hash Function 3: (Key - R)% R,

For the given key values the smallest key is 8.

Hence,

the greatest prime number less than the smallest key is 7

the index valuse are calculated as [ for ex: (200-7) % 7 = 4 ]

4, 1, 1, 1, 0, 2, 3

so there are 3 collisions

Therefore, the number of collision is minimal for hash Function 1. Hence the perfect hash function for the given set of keys is hash Function 1:   Key % 22

Know the answer?
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
Similar Questions
READ THE CASE STUDY AND ANSWER THE FOLLOWING QUESTIONS 2nd CASE: An Unexplained Death A 65-year-old...
READ THE CASE STUDY AND ANSWER THE FOLLOWING QUESTIONS 2nd CASE: An Unexplained Death A 65-year-old man of Scandinavian descent was rushed to the Emergency Room of your local hospital after a family member discovered him unconscious in his home. The woman who dialed “911” told the dispatcher that the man, her brother, was the local librarian of the past 10 years and had no spouse or children. She reported that they had spoken the day before, and he had...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Actually a HISTORY question: what tactics does Einhard use to portray Charlemagne in "Life of Charlemagne"...
Actually a HISTORY question: what tactics does Einhard use to portray Charlemagne in "Life of Charlemagne" and what tactics does Procipius use to describe Justinian in a positive light in the "Nika Riots"? Ive posted both excerpts. "Life of Charlemagne" Charles the Great, (Charlemagne in French) reigned 768-814 as king of the Franks and the most important ruler of the Carolingian Dynasty, conquering lands in what is now Germany, France, Spain, and Italy. On Christmas Day 800 C.E., Pope Leo...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT