Let $f: A→B$ be a function between non-empty sets $A, B.$
(a) Prove that f is injective if and only if there exists a function $g: B→A$ such that $g◦f = idA$, where $idA: A→A,$ is the identity function.
(b) Prove that $f$ is surjective if and only if there exists a function $g: B→A$ such that $f◦g = idB.$
my concern is since $f$ is not surjective then how can we define $g=f^{-1}$ taking domain as whole $B$? thanks for any suggestion on existance of such $g$