TITLE: Help with proving Schröder Bernstein theorem
QUESTION [7 upvotes]: I am trying to prove  Schröder–Bernstein theorem
 myself but I am stuck. Here is my try.

Let $f:A \rightarrow B$ and $g:B \rightarrow A$ be injective functions for sets $A$ and $B$. Define $h: A \rightarrow B$ as follows:
$$ h\left(x\right) = 
     \begin{cases}
       f(x) & \nexists b : g(b)=x \\
       g^{-1}(x) & \text{otherwise}
     \end{cases}
   $$
$h$ is a well defined function because $g$ is injective and it is onto as well.
I am stuck at this point because $h$ can be surjective. However for each $x \in B$, there can be at most $2$ distinct elements of $A$ which map to $x$. I think this observation can be used to make use of an argument similar to Hilbert's paradox but I am not able to come up with it.

I don't need a complete solution, a hint in the right direction would be much appreciated.

REPLY [3 votes]: Good try but it won't quite work. For $a\in A$ let $a\in E$ if the sequence $h^{-1}(a),\; g^{-1}h^{-1}(a),\; h^{-1}g^{-1}h^{-1}(a),$... is either endless or must stop after an even number of terms, and $a\in O$ if the sequence must stop after an odd number of terms (including possibly just one term). 
Let $f(a)=h(a)$ if $a\in O$ and $f(a)=g^{-1}(a)$ if $a\in E.$  Observe that  $a\in E$ iff  $h(g(a))\in E.$  Use this to show that $f:A\to B$ is a bijection.