Let $f$ be a binary relation defined on set $S$, which contains numbers from $1$ to $n$. It is also given that number of $|\text{Img}(f)| \le k$. I want to store the function $f$ such in way such that space required is minimum.
I am trying to store the function with a graph, but number of edges turnout to quadratic in $n$.
Question : How to store the relation $f$ space efficiently?