Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, Im currently learning about hashing. Im still not comfortable with hashing and was wondering if you could provide any hints on how to get
Hi, Im currently learning about hashing. Im still not comfortable with hashing and was wondering if you could provide any hints on how to get started with this question.
1. [14] In this question, we wl study a pitfall of quadratic probing in open addressing. In the lecture, we showed for quadratic probing that we need to be careful choosing the probe sequence, since it could jump in such a way that some of the slots in the hash table are never reached. (a) Suppose that we have an open addressing hash table of size m -7, and that we are using linear probing of the following form h(k, i) = (h(k) + i)nod m, i=0,1,2 where h(k) is some arbitrary hash function. We claim that, as long as there is a free slot in this hash table, the insertion of a new key (a key that does not exist in the table) into the hash table is guaranteed to succeed, i.e., we will be able to find a free slot for the new key. Is this claim true? If true, concisely explain why; if not true, give a detailed counterexample and justify why it shows that the claim is false (b) Now, suppose that we have an open addressing hash table of size m-7, and that we are using quadratic probing of the following form h(k, i) = (h(k) + i2) nod m, 1-0, 1,2 . . . where h(k) is some arbitrary hash function. We claim again that, as long as there is a free slot in this hash tablo the insertion of a new key into the hash table is guaranteed to succeed, i.e., we must be able to find a free slot for the new key. Is this claim true? If true, concisely explain why; if not true, give a detailed counterexample and justify why it shows that the claim is false (c) If either of your answers to (a) and (b) is Ise", then it means that some of the slots in the hash table are essentially "wasted", i.c., they are free with no key occupying them, but the new keys to be inserted may not be able to use these free slots. In this part, we will show an encouraging result for quadratic probing that says "this waste cannot be too bad" Suppose that we have an open addressing hash table whose size m is a prime number greater than 3, and that we are using quadratic probing of the following form h(k, i) = (h(k) t i*) mod m, i = 0, 1, 2 Prove that, if the hash table contains less than [m/2] keys (i.c., the table is less than half fu), then the insertion of a new key is guaranteed to be successful, i.c., the probing must be able to reach a free slot Hint: What if the first m/2 probe locations for a given key are all distinct? Try proof by contradiction. 1. [14] In this question, we wl study a pitfall of quadratic probing in open addressing. In the lecture, we showed for quadratic probing that we need to be careful choosing the probe sequence, since it could jump in such a way that some of the slots in the hash table are never reached. (a) Suppose that we have an open addressing hash table of size m -7, and that we are using linear probing of the following form h(k, i) = (h(k) + i)nod m, i=0,1,2 where h(k) is some arbitrary hash function. We claim that, as long as there is a free slot in this hash table, the insertion of a new key (a key that does not exist in the table) into the hash table is guaranteed to succeed, i.e., we will be able to find a free slot for the new key. Is this claim true? If true, concisely explain why; if not true, give a detailed counterexample and justify why it shows that the claim is false (b) Now, suppose that we have an open addressing hash table of size m-7, and that we are using quadratic probing of the following form h(k, i) = (h(k) + i2) nod m, 1-0, 1,2 . . . where h(k) is some arbitrary hash function. We claim again that, as long as there is a free slot in this hash tablo the insertion of a new key into the hash table is guaranteed to succeed, i.e., we must be able to find a free slot for the new key. Is this claim true? If true, concisely explain why; if not true, give a detailed counterexample and justify why it shows that the claim is false (c) If either of your answers to (a) and (b) is Ise", then it means that some of the slots in the hash table are essentially "wasted", i.c., they are free with no key occupying them, but the new keys to be inserted may not be able to use these free slots. In this part, we will show an encouraging result for quadratic probing that says "this waste cannot be too bad" Suppose that we have an open addressing hash table whose size m is a prime number greater than 3, and that we are using quadratic probing of the following form h(k, i) = (h(k) t i*) mod m, i = 0, 1, 2 Prove that, if the hash table contains less than [m/2] keys (i.c., the table is less than half fu), then the insertion of a new key is guaranteed to be successful, i.c., the probing must be able to reach a free slot Hint: What if the first m/2 probe locations for a given key are all distinct? Try proof by contradictionStep 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