Question: Question 4 This question is about hashing. (a) Briefly explain why hash tables are useful for storing many integers. [5 marks] (b) Explain how hash

 Question 4 This question is about hashing. (a) Briefly explain why

Question 4 This 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!