Does a inverse function need to be either surjective or injective?

That depends on subtleties of your definition of inverse function. If you expect a function $f\,:\, A \to B$ to have an inverse $f^{-1} \,:\, B \to A$, then $f$ needs to be surjective. If it is not, there are some $b \in B$ that aren't reached by $f$ at all, so how would you define $f^{-1}$ for such elements of $B$?

However, any injective $f\,:\, A \to B$ can be made surjective by simply restricting $B$, i.e. by setting $\widetilde{B} = \{f(a)\,:\, a\in A\}$ and redefining $f$ as $f \,:\, A \to \widetilde{B}$. That redefined $f$ then has an inverse $f^{-1} \,:\, \widetilde{B} \to A$.

Note, however, that while this makes the concatenation $f^{-1} \circ f$ the identity funtion on $A$, it does not make $f \circ f^{-1}$ the identity function on $B$, only on $\widetilde{B} \subsetneq B$.

Thus, if $f \,:\, A \to B $ is injective but not surjective, it has a left-inverse, because we can find an $f^{-1}$ as above with the property that $f^{-1} \circ f$ is the identity on $A$. But it does not have a right-inverse, because we won't find a $f^{-1}$ such that $f \circ f^{-1}$ is the identity on $B$ - the best we can achieve is an identity on $\widetilde{B}$.

Similarly, if $f \,:\, A \to B$ is surjective but not injective, it has a right-inverse, but no left-inverse.


A function has an inverse if and only if it is both surjective and injective. (You can say "bijective" to mean "surjective and injective".)

Khan Academy has a nice video proving this.

edit: originally linked the wrong video.


Hint: if function $ f : A \rightarrow B $ was not surjective, how would we define $ f^{-1} : B \rightarrow A $ for an element that was not in the image of $ f $?