Suppose f is injective. Then we assume that f is not surjective
and find a contradiction. Let x ∈ X be such that f(y) 6= x for any y ∈ X.
However, since each x ∈ X must go to an element of X, we must have two
elements in X mapping to the same element. (Note that it is importantlli’s
X be finite for this to work!) This contradicts the injectivity. Thus if f is
injective, it must be surjective.
Now suppose that f is surjective but not injective. Let x, y ∈ X so that
f(x) = f(y) but x 6= y. This means that there are not enough elements
left to map to each element of X since we have essentially used two of them
to map to one element. Thus f cannot be surjective. Both of these are
examples of the pigeonhole principle. It states if you have N “pigeonholes”
and M > N pigeons, some pigeons must go into the same box