Let $S$ be a semigroup. If for any $x,y\in S$, $x^2y=y=yx^2$, then prove that $S$ is an abelian group.
My solution goes like this:
If for any $x,y\in S$, we have $x^2y=y=yx^2$. Then this implies $x^2=e$. So, $x=x^{-1}$ and this holds $\forall x\in S$. Hence, if $a,b\in S$ then $(a\cdot b)\in S$ and $$(a\cdot b)=(a\cdot b)^{-1}=b^{-1}a^{-1}=ba.$$ Thus, $S$ is an abelian group.
Is the above solution correct? Is it valid? If not, then where does it go wrong?
Your supposed proof assumes that there is an identity in the semigroup, which isn't always a given; you have to show it. See here for a real proof.