I tried to prove that the sets $\mathbb{N}$ and $\mathbb{N^2}$ have the same cardinality and I concluded the following:
Consider the function $f:\mathbb{N}\rightarrow \mathbb{N^2}$ that achieves the mapping:
$ \begin{cases} 1 \rightarrow (0,0) \end{cases} \\ \begin{cases} 2 \rightarrow (1,0) \\ 3 \rightarrow (1,1) \\ 4 \rightarrow (0,1) \end{cases} \\ \begin{cases} 5 \rightarrow (2,0) \\ 6 \rightarrow (2,1) \\ 7 \rightarrow (2,2) \\ 8 \rightarrow (1,2) \\ 9 \rightarrow (0,2) \end{cases} \\ \quad \vdots$
This way $\forall k \in \mathbb{N}\cup\{0\}$ we construct the function:
$f(n) = \begin{cases} \begin{aligned} &(\sqrt{n-1},0) \\ &(\sqrt{n-1},1) \\ \vdots \\ &(\sqrt{n-1},\sqrt{n-1}-1) \\ &(\sqrt{n-1},\sqrt{n-1}) \\ &(\sqrt{n-1}-1,\sqrt{n-1}) \\ \vdots \\ &(1,\sqrt{n-1}) \\ &(0,\sqrt{n-1}) \end{aligned} && \begin{aligned} &, n=k^2+1 \\ &, n=k^2+2 \\ \\ &, n=k^2+k \\ &, n=k^2+k+1 \\ &, n=k^2+(k+1)+1 \\ \\ &, n=k^2+(2k-1)+1 \\ &, n=k^2+2k+1=(k+1)^2 \end{aligned} \end{cases}$
Is the above mapping correct? If not then why? If yes then how can I prove rigorously that this function is bijective?
First, you need to define whether $0 \in \Bbb N.$ On the left of your correspondence you do not allow it, but on the right you do. Either way works fine for this purpose, but it makes changes in your bijection. There are many bijections that prove what you are trying to prove. Yours is a fine example. You need a floor function to make your square roots be natural numbers. The point is that the $n$s from $k^2+1$ to $(k+1)^2$ cover the $2k+1$ points on two sides of the square of side $k$ that haven't been covered before. The $n$s from $1$ to $k^2$ cover the square $[0,k-1] \times [0,k-1]$ If you write $n=k^2+p$ where $k$ is the maximal value to make $p$ nonnegative you can define $f(n)$ in a couple lines, one for each side of the square. Then for any ordered pair you can find the $n$ that maps to it.