# Hash tables

• 12-01-2010
marya
Hash tables
I have a task... And idea- and don't know how to implement it.

So, we need to create a set of integers of 100 000 elements (keys) and a range of 50 000 integers (hash-table). The keys are natural numbers from 1 to 100 thousand. Make your own hash function. The idea of the task is suitable for placing the keys in the hash table until it has a place, and then it stops putting the keys, where the index element in the hash table determines the hash function. If you want to take the place of either the collision. This collision is necessary to calculate and print them on the screen as the only output data. The best hash function = minimum number "crashing"

My idea for Hash table is:

Code:

```int hash (int x)  {     return (x - 1) % 50000;  }```

And have a problem to write this in the arrear of code... Can anyone solve my problem and write it?

Thanx a lot,

Marie
• 12-01-2010
anduril462
Many people here can solve and write your problem for you, however, nobody here will. Read the following, try it yourself, and come back with your attempt. Then we will help you find your problems. Nobody here wants to do your homework for you (unless perhaps you pay us...but we're professional programmers, expect consulting rates around \$100/hour).

C Board - Announcements in Forum : C Programming
C Board - Announcements in Forum : General Programming Boards
• 12-01-2010
quzah
Code:

`int hash( void ) { return rand() % 50000; }`
Good enough for who it's for.

Quzah.
• 12-01-2010
marya
Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> int Unos(long a[], long broj) { int h, broj1 = broj; int br=0; int test = 0; long N=50000; do { h = broj1; if (a[h] < 1) { a[h] = broj; test = 1; break; } else {     broj1++;     br++; } } while (broj1 < (broj + N) && test!=0); return (br); } int main() { long niz[100000],i,a[50000]; int br=0; for(i=0;i<100000;i++) niz[i]=i; for(i=0;i<50000;i++) a[i]=0; for(i=0;i<100000;i++) br=Unos(a,niz[i]); br=br+br; printf("br =%d",br); for(i=0;i<50000;i++) printf("%d",a[i]); printf("%d",a[0]); printf("\n\nbr =%d",br);     return 0; }```
this is what i wrote but don't know how to write hash :S
• 12-01-2010
iMalc
Fix your indentation or I'm not looking at it, and many others will feel the same way.