I have already done a fixed 2d array version of a hashtable in c , now I need to
ID: 3874705 • Letter: I
Question
I have already done a fixed 2d array version of a hashtable in c , now I need to do a dynamic 2d array version of the hashtable. How is the code going to change ? And also how can I calculate the hash function since the size of hashtable is not fixed ? Thanks. I have already done a fixed 2d array version of a hashtable in c , now I need to do a dynamic 2d array version of the hashtable. How is the code going to change ? And also how can I calculate the hash function since the size of hashtable is not fixed ? Thanks.Explanation / Answer
- maintain size of size of array and total elements added to hashtable in globle variable.
- For any put(add) operation to hashtable, check if array is full or not. if not full then add otherwise create array with double size of previous array and iterate through old array and insert all elements to new array using position function.
- For remove operation, remove element from array then check if number of elements in array is less than array size then create new array with half of the size of previous array and iterate through old array and insert all elements to new array using position function.
- Position Function- this fuction will return postion(index) of element in hashtable.
1) first get hash value of element using hash function
2)then return position(index) using this formula
* index = hash_value % (size_of_array - 1)
*** note size_of_array we are maintaining globally
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.