Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ihis question is about hashing. (a) Briefly explain why hash tables are useful for storing many integers. [5 marks] (b) Explain how hash functions are
Ihis question is about hashing. (a) Briefly explain why hash tables are useful for storing many integers. [5 marks] (b) Explain how hash functions are used to build a hash table. Ignore collisions and illustrate your answer by considering a function h(k)=k mod 5 hashing into a table with 5 slots. [5 marks] (c) Briefly explain the concept of a collision in the context of a hash function. Give an example demonstrating this concept. [5 marks] (d) Suppose that T is table with m slots and h(k,i) for I=0,1,,m is a hash function that hashes k to j=h(k,0) if slot j of T is unoccupied and otherwise probes T for an available slot. Write a pseudocode algorithm INSERT(T, k) that attempts to insert k in table T. INSERT should return the slot index if the insertion was successful; an error warning should be returned if insertion fails. [5 marks] (e) Explain why linear probing can lead to long runs of occupied slots. [5 marks] (f) Suggest a general strategy to overcome the pathology of part (e) and provide an example of a specific hash function that ameliorates the problem. [5 marks]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started