LP Live Advanced - Hashing Problem

What if we multiply each letter with a different prime no. each time?
FOR e.g we take BAT and BATman and take first 3 letters from both which will be “BAT” and multiply it with 3^0,3,3^2 in case of Bat but incase of Bat from Batman we can multiply with 5^0,5,5^2
This way we can choose different primes for every word in a code and then mod it with table size, it may create less no. of collisions.

Hello @MadHawk ,

Yes, this way the collisions would decrease surely.
But, here comes the problem,
If you’ll keep on changing the prime number, then how would you keep track of elements.
The searching operation would become complex.

The reason for taking same prime number, is for easier access from the hash table.

Hope, this would help.
Give a like, if you are satisfied.

1 Like

I am not able to make the insert code in Code::Forces. It says can’t build. In dev c++ too, errors like this are coming. How do I run the code??

Can you send your code?


It’s the main/Hashtable.cpp file

It’s the header/Hashtable.h file
In code::blocks both are in same project.

As per my knowledge you have to create two different files of same name for the code that you wants to include in another cpp file:

  1. The first file is of extention .h and it includes the prototypes of functions that you wants to import.
    Make sure to put a bogus define at the top of each of your .h files to prevent accidental re-inclusion, as in:

    #ifndef MYFILE_H_
    #define MYFILE_H_

    // your code goes here

    #endif

  2. The second file is .cpp file with same name and it contains the definitions of the functions you have specified in file one.

You can refer to this. for better understanding of the concept.

Hope, this would help.
If you still have doubts, feel free to ask.

Couldn’t execute the code still. Can you do the changes in the ide. Then I will try again running it.

Sure, I’ll send the modified version of your code soon.

Please send the modded version