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.
Help with double hashing table
Collapse
X
-
Originally posted by saraSSI 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. -
Originally posted by saraSSyes the best way to do it example code maybe thanks
(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.)Comment
-
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_Dhas hing(int seed,int n)
{
int *table,i,duplic ates,key;
unsigned h,h2;
n=nextPrime(n);
table=(int*) malloc(n*sizeof (int));
if (table==NULL)
{
printf("choked in duplicates_qsor t()\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) ;
}Comment
Comment