Question

In: Computer Science

PYTHON--- regarding a hash table, why would it be bad to delete an item to successive...

PYTHON--- regarding a hash table, why would it be bad to delete an item to successive searches or insertions that uses open addressing

Solutions

Expert Solution

Open addressing is one of the collision resolution method. In open addressing, all the keys are stored within the table itself. Whenever a collision occurs, the next location will be probed using several methods like linear probing, quadratic probing etc.

So the main problem in open addressing is that when the location from the hash function is "k" the actual value may not be present in the exact location "k". It may be moved to other locations based on probe technique used.

Consider a hash of 3 nodes of which first 2 are already occupied. Now assume new key also hashed to slot 1, and due to some resolution technique it is placed in slot 3.

Now if we want to delete slot 2 and we directly delete it, a huge problem will occur. Assume we deleted slot 2 directly. So later when the search for slot 3 is asked, it will point to slot1 (as assumed above). As the value in slot 1 is not the required value, the probe goes to slot2.

But as we deleted it, it will be empty and probe thinks that the value requested is not present in the hash table.

So when a key is deleted, we should explicitly mark it as deleted so that the search will go past the deleted node.

So in the above case when we mark slot 2 as deleted, the probe now goes to slot3 instead of stopping at slot 2, and finally gets the value in slot 3.

So in case of deletion we should be extra careful than consecutive searches and insertions in case of open addressing.


Related Solutions

Write an algorithm to delete an element from a hash table that uses linear probing as...
Write an algorithm to delete an element from a hash table that uses linear probing as its clash resolution strategy. Analyze your algorithm and show the results using order notation?
I'm working on a to-do list program in Python 2. I'm trying to delete an item...
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue:...
1. In terms of security, why would you not use rm command to delete files? 2....
1. In terms of security, why would you not use rm command to delete files? 2. Shred and dd are tools used to securely delete files. Which is the best tool for securely deleting a file from a system and why? Consider the limitations of each tool when choosing your answer. 3. What encryption is used to encrypt HTTP traffic (HTTPS)? 4. The CIA triad , confidentiality, integrity, and availability represent the three goals for cybersecurity. Which goal(s) does/do encryption...
Regarding Python. 1. How would you write a regex that matches the hour of the day...
Regarding Python. 1. How would you write a regex that matches the hour of the day from the extracted line shown below? (The highlighted portion) From [email protected] Sat Jan 5 09:14:16 2008 Question options: ˆFrom .+ [0-9] ˆX-.*: [0-9.]+ [0-9]: ˆFrom .* [0-9][0-9]: ˆFrom .* ('ˆX\S*: ([0-9.]+)', line) A _____________ sign at the end of the regular expression indicates that the string must end with the specified regex pattern. Question options: question (?) caret (^) dollar ($) 0 / 1...
Why is the profitablity index bad for valuing mutually exclusive projects, and why would NPV be...
Why is the profitablity index bad for valuing mutually exclusive projects, and why would NPV be a better valuation method?
Complete each of the columns on the table below, indicating in which section each item would...
Complete each of the columns on the table below, indicating in which section each item would be reported on the statement of cash flows (operating, investing, or financing), the amount that would be reported, and whether the item would create an increase or decrease in cash. For item that affect more than one section of the statement, indicate all affected. Assume the indirect method of reporting cash flows from operating activities. The first item has been completed as an example....
Explain the advantage of Fc fusion protein drugs. Why would it be a bad idea to...
Explain the advantage of Fc fusion protein drugs. Why would it be a bad idea to give an immunosuppressed patient a live attenuated vaccine? Why might an antibody to one serotype be ineffective against a different serotype (antigenic variation)? just short answer
Regarding requirement #4: What impact would an outlier have? Regarding requirement #5: Why is it important...
Regarding requirement #4: What impact would an outlier have? Regarding requirement #5: Why is it important to look at dispersion? Why is standard deviation a better measure of dispersion than the range?
how do companies account for bad debt? Why would they use an allowance account instead of...
how do companies account for bad debt? Why would they use an allowance account instead of directly crediting A/R? What are the various methods of accounting for bad debt? Describe the differences in how the expense is calculated.
In python explain why would we want to read a file line by line instead of...
In python explain why would we want to read a file line by line instead of all at once?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT