Answered step by step
Verified Expert Solution
Question
1 Approved Answer
It is of course possible that two keys we want to insert into the hash table hash to the same value. It is a consequence
It is of course possible that two keys we want to insert into the hash table hash to the same value. It is a consequence of the Birthday Paradox enwikipedia.orgwikiBirthdayproblem that this will be far more likely than what our intuition might suggest. As a result, we need a way of distinguishing between keys with the same hash value. There are various methods to resolve collisions. For this assignment, you will be implementing a hash table with linear probing to resolve collisions. When two keys hash to the same index, linear probing searches the table for the closest following free location and inserts the new key there. Table resizing It can be shown when you take CMPT you may be asked to actually show it that hash tables maintain an average O time complexity for inserts and lookups only so long as the table is no more than full. Having fewer empty spaces increases the chance of collisions, which leads to longer probing times. Since your hash table needs to store an arbitrary number of keys and values, this means the size of your table may have to grow to accommodate additional inserts. To do so your hash table will have to keep track of the current number of elements in the table and its capacity. When the load ratio exceeds on an insert, the htinsert function will trigger a table resize operation. When this happens, additional memory needs to be allocated for the larger table. Consider what is the most practical solution: resizing the current array, or creating a new larger array. One of your design decisions is where to store the table capacity and current number of elements. Question: what will need to happen to all the keys and values already inserted into the hash table? Will they reside in the same position as before the resize operation took place? In your design document answer this and explain what needs to happen during resizing. Data Structures In your design document, indicate what data structure you will use to represent your hash table, and what constitutes an entry in the table. Decide what information will be stored in each entry for a keyvalue pair. What will be the chosen datatype for keys? What will be the chosen datatype or data structure for values? This decision might be best made after reading the specifications of the postal code collator program below. Provide type declarations as appropriate, and describe at a high level how they will be used in insertion, lookup, and deletion operations.
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