Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1) Assume that you bave a hash table with size 6 and the following bashing function: h (key) key % table_size. (a) Draw the tash

image text in transcribed

Q1) Assume that you bave a hash table with size 6 and the following bashing function: h (key) key % table_size. (a) Draw the tash table alter inserting the following sequence of ekments in order. Assume that we are using separate chaining (lists) for resolving collisions and that the elements are inserted at the tail of each list. (b) Suggest a hash table size that will result in ne collixinns for the above sequence of insertions. The hashing furction remains the same. Briefly justify your choice. Q2) Consider the following lash function implementation: b(key) = key 2% \% size a) Assume that we create a hash tahle with array sire 4. Dras: (next to the above code) the table and its contents after we insert the following values in order: 1,4,5,6,3,15,10,11. Nete that the hash function that we are using here is different from the one that we ased in class b) Did you observe any efficiency problem in the above hash example? If yes, explain the problem and suggest a solutson. If no, explain why it as efficient. Yes, there is efficieney problem; half of the lashl array cells are not used and the collision among data is sort of high. This is happening because of the lash fasction distributing the data such that even numbers go to lirst list (index 0) and odd numbers go to the third list (index 2). And this happens from (val 2 ). A suggested solution is to change hash function to spread data more evenly aeross the hash lists, esample will he val % size-Another solution would be to increase the hash size. Q3) Suppose that we cossider using an ardered DI.L in each hash bucket instead of an unordered DLL. Compare the asymptotic complexities of the operations shown in the table below for each of these two implementations (ordered DI.L. vs unordered DL.L.). Assume that the namber of elemerns in the bash table is N, the number of buckets is M and that each bueket las exuctly 2 . elements (N/M)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions