I need to write a program that will determine the number of duplicates in a table of integers by using ordinary double hashing with initialization, I need to use double hashing with each entry in the hash table initialized to indicate that it is unused.
I need to write a program that will determine the number of duplicates in a table of integers by using ordinary double hashing with initialization, I need to use double hashing with each entry in the hash table initialized to indicate that it is unused.
And did you have a question for us? Were you wondering the best way to go about this, was there a question with the hashing itself...?
yes the best way to do it example code maybe thanks
Cna you tell me how you'd do it, in a few sentences?
(Sorry, but I'm not going to give you the code... not only would that defeat the purpose of you learning it, but I am also too busy, though I will be more than happy to help you with it.)
when I use the qsort I get some duplicates and I'm trying to do the same thing with double hashing but I get no duplicates what I'm doing wrong?
void duplicates_Dhashing(int seed,int n)
{
int *table,i,duplicates,key;
unsigned h,h2;
n=nextPrime(n);
table=(int*) malloc(n*sizeof(int));
if (table==NULL)
{
printf("choked in duplicates_qsort()\n");
exit(0);
}
for (i=0;i<n;i++)
table[i]=-1;
srandom(seed);
for (i=0;i<n;i++)
{
key=abs(random());
printf("%d \n",key);
h=(key % n);
h2=(( key % ( n - 1 )) + 1);
while (table[h]!=-1)
h = ( h + h2 ) % n;
table[h] = key;
}
duplicates=0;
for (i=1;i<n;i++)
if (table[i-1]==table[i])
duplicates++;
printf("%d duplicates \n",duplicates);
can somebody help me ? my double hashing loop is not working it looks like should be working but I dont know
for(i=0;i<m;i++)
{
key=abs(random());
h=((key+i)%m);
h2=(1+(key%(m-1)));
h=((h+(i*h2))%m);
if(table[h]==-1)
table[h]=key;
}