Search code examples
algorithmcomputation-theorynp

Is mapping array elements to perfect hash indexes NP Complete?


Assuming I have a set of integers that can range from 0 to INT64MAX, but I know the set in its entirety so I can generate a perfect hash.

If I want to use these hashes as array indices, I need to modulus with the size of the array I want to store this in.

This brings a problem where I want to find a non-colliding set for my hashes that map to integers such that minimal array size is needed and I still have no collisions.

Is this NP complete? It "feels" NP Complete.


Solution

  • No.

    There exist algorithms that construct perfect hashes (even minimal perfect hashes) in linear time. See for example the CMPH docs which list a couple of them.

    Linear time means deterministic polynomial problem, thus the problem lies in P. P is contained in NP, but the problem certainly is not at least as hard as the hardest problems in NP, thus it is not in NP-hard.

    NP-complete is defined as being in both NP and NP-hard. Therefore, it is not NP-complete.