Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The below is my hash function and insert function : When I run the program the b

ID: 3874842 • Letter: T

Question

The below is my hash function and insert function :

When I run the program the below output is given :

Data at index 0 in Hash Table:
Letter Number  
--------------------------------
P 10 A 8   
Data at index 1 in Hash Table:
Letter Number  
--------------------------------
L 11
Data at index 2 in Hash Table:
Letter Number  
--------------------------------
R 3 C 4 H 5 M 9   
Data at index 3 in Hash Table:
Letter Number  
--------------------------------
S 0 X 7   
Data at index 4 in Hash Table:
Letter Number  
--------------------------------
E 12  

This out put is wrong as it should be like the one in the picture below. It was given to me as a guide to make a hash table with and array for access of the computed hashes and with linked lists storing key-value pairs with collisions.

Kindly can you tell me whether there is something wrong in my code ?

Thanks.

key hash value rst rst st null SequentialSearchST objects L 11 P 10 rst P 3 10 311 E 0 12 Hashing with separate chaining for standard indexing client

Explanation / Answer

Your output is different because your hash function does not return the same hash value as given in the example.

for example:

ascii value of letter A is 1.

your hash value is = 1 %5 = 1

but in an example pic hash value is 0.

But your hash function is also valid.

your code is alright.

Your printing function is printing the wrong index.

Data at index 0 in Hash Table:
Letter Number  
--------------------------------
P 10 A 8

letter A has index will be 1 % 5 =1

but your print function is printing as index 0

it is printing index -1 for each index, except 0 for which it is printing as 4.

your insertion code is perfectly fine.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote