Hashing...how does it work?

So I have this problem and the input need to look like this
ID Name
26145 RADY
3437 FRANZ



and the output like this
Key Name
33 RADY
365 FRANZ


I am really confused on the entire concept? Where is the output getting those numbers? Plz help
Last edited on
Which hash function do you use?
I am not sure this is what the instructions says.. I am totally lost.


Each of these entries must be stored inthe first 512 indices of a vector<string>.The identi er determines which index the last name is stored. For this program, the index is determined by the hash function described in the introduction instead of the identi er value. Collisions must be handled by incrementing the hash key until an unoccupied index is found. A function hash must be declared and used in the program with the following prototype.

int hash(int k, int m);
You use the modulus operator.

( number % m ) is the integer remainder when number is divided by m.

The possible remainders are 0 to m-1.

When m is evenly divisible by m, ie, number = m*i for some integer i, then the remainder is 0, and so number % (m + 1) will then be 1.

If number mod m maps integers to values between 0 and m-1, what does this tell you about how you can map the numbers in your problem to values in the range of the your valid indices?
could u plz give me like a pseudocode on how to approach this problem?
For this program, the index is determined by the hash function described in the introduction.
So "the introduction" tells you what hash function to use. Maybe that's the introduction to the problem?
OP said:
could u plz give me like a pseudocode on how to approach this problem?


htirwin already did, reread his second sentence. If it still hasn't sank in then:
 
ID % Size_Of_Index = // ?? 
i am having a hard time inputting the name with the ID? I put in the vector as a vector< pair<int,string> > seq ; but for some reason its not working?
do not store the hash number. The hash is the index where you stored the data. Since the hash can be calculated, it makes finding the data much quicker than scanning through the entire container. So, what happens if 2 pieces of data have the same value? Well, they both can't be stored in the same place! The instructions clearly state that you find the next available index to store the data in.
never mind got it thanks everyone
Topic archived. No new replies allowed.