Minimal perfect hash function

173 Views Asked by At

If I have list of $n$ unbounded different random integers, is it always possible to find such integers $\alpha$, $\beta$ and $\gamma$, that function $$f(x)=((\alpha\times x+\beta)\mod\gamma)\mod n$$ will have different values for all numbers in the list?

If yes, is the same possible when $\beta=0$?

For example, for list $\{17, 1, 12, 4, 5, 0, 7\}$ such function exists:
$$f(x)=((25\times x)\mod29)\mod n$$ It returns following values: $\{5, 4, 3, 6, 2, 0, 1\}$.

However, for list $\{5, 13, 23, 37, 47, 61, 6, 7, 8, 9, 11, 12\}$ I'm not able to find such function, that means that there is no such or numbers are big enough to be not founded (I performed computer search for $0\lt\gamma\lt5000$). There must be problem in length $n=12$ and $61=12*5+1$, because when I change 61 to 62 - function is easy to find.