include<iostream>

using namespace std;
int main()
{

``````int Partnumber[15] = {112,130,156,173,197,150,166,113,123,143,167,189,193,117,176};
int Quantitynumber[15] = {12,30,56,17,19,50,66,13,12,14,16,18,19,11,76};
int hashTable[19][2];
int collisions = 0;
int index = 0;

for(int i = 0; i<15;i++)
{
index = (Partnumber[i] % 19);
hashTable[index] = Partnumber[i];

if (hashTable[index] != 0)
{
do{
index++
}while(hashTable[index]!=0)
}
if(index >= sizeOf(hashTable) )
{
index=0;
}
else
{
hashTable[index] = Partnumber[i];
}
}

return 0;
``````

}

First of all I must say that I'm am a newbie to hashing and I have an assignment for class. I'm not going to type the whole problem out but I'm having a problem creating a hashing function and handling collisions. I tried to do linear probing in the above code but I can tell that it won't work. Can somebody tell me a more efficient way of doing this. Here's a link to the problem:

I'm not asking anybody to write this program for me, but i need some direction with this hashing and linear probing algorithm. Thanks :D

Note: I have a two dimensional array to hold the part number along with it's quantity in separate columns

Edit: Also a problem that I'm having is starting back to the beginning of the hashTable if the calculated index is 19. As you can see I'm in desperate need of some help

## All 3 Replies

See Knuth, Volume 3, Sorting and Searching, Addison-Wesley Pub.

I tried to do linear probing in the above ...

Looking at the link you gave, it looks like they want you to use link-lists for the collisions because in the section were it talks about

b. when requested, analyze the efficiency of the hashingalgorithm for this set of data. the printout format is
percentage of Prime Area Filled: xx%
Average nodes in linked list: nn