How to show the integers have same cardinality as the natural numbers?

How would I show the following have a bijection. Which is one to one and onto ofcourse.

$\mathbb{Z}\rightarrow \mathbb{N}$

I know I need to find a function. But I do not see the pattern that makes integer go to natural. I already did this problem from natural to integer but now I want to see it done this way.

I have listed some numbers

$,..,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,..$

$1,2,3,4,5,6,7,8,9,10,11,12,13,14,.$


Solution 1:

I like the one that snake around, $0, -1, 1, -2, 2, -3, 3,\ldots$

So it goes

$$\begin{cases}f: \Bbb N\to \Bbb Z \\ f(2n)=n-1 \\ f(2n-1)=-n\end{cases}$$

If you want it to go the other way, you just reverse the idea and compute the inverse of $f$.

Solution 2:

Your list has absolutely no pattern, because you're doing it "wrong", in the sense that you are not writing it in a way that a pattern emerges.

Of course there is no order preserving function, so writing both sets with their natural order will promise you that there is no reasonable pattern. Instead write the natural numbers, and then try to write the integers:

$$\begin{array} & 1 & 2& 3& 4& 5& 6& 7& 8&\ldots\\ 0 & 1& -1& 2& -2& 3& -3& 4&\ldots \end{array}$$

This gives rise to a bijection from $\Bbb N$ onto $\Bbb Z$. Now just find its inverse.

(Note that it is in general easier to find "pattern" when $\Bbb N$ is the domain, because the list does not require you to go into two directions.)