Question: The below is my hash function and insert function : int hashCode( int letter) { //hash code that will return the index of array return

The below is my hash function and insert function :

int hashCode(int letter) { //hash code that will return the index of array   return letter % 5; } void insert(int letter,int number) { int hashIndex = hashCode( letter); struct node *newnode = createNode( letter, number); /* head of list for the bucket with index "hashIndex" found for the key enetered */  if (!hashTable[hashIndex].head) { hashTable[hashIndex].head = newnode; hashTable[hashIndex].count = 1; return; } /* adding new node to the list */  newnode->next = (hashTable[hashIndex].head); /*  * update the head of the list and no of  * nodes in the current bucket  */  hashTable[hashIndex].head = newnode; hashTable[hashIndex].count++; } 

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.

The below is my hash function and insert function : int hashCode(int

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!