How to figure out if a piecewise function is injective, surjective or bijective? I have the following function $g:\mathbb{N} \rightarrow\mathbb{Z}$ defined as follows:
$$g(n)=\begin{cases}
-\frac{n+1}{2}&\mbox{if }n\mbox{ is odd}\\
\frac{n}{2}&\mbox{if }n\mbox{ is even}\\
\end{cases}
$$
I'm trying to figure out if this function is
1) Surjective but not Injective
2) Injective but not Surjective
3) Bijective
Now I'm trying to figure out how to solve it. What I tried so far is solve for $y = -\frac{n+1}{2}$ to get $-2y+1 = n$ and figured that when $y=2$ then $n = -3$ which is not a natural number and so then it can't possibly be surjective.
Yet for some reason, according to my professor this is bijective which means it is also surjective. I would really appreciate some help in solving these. Thank you!
 A: Your easiest bet is to go back to the definitions of injectivity and surjectivity.
To see if it is a surjection, let $m\in\mathbb Z$ be given and see if you can find an $n\in\mathbb N$ such that $f(n)=m$.  The work that you showed in the beginning will be a little more productive now that you have the correct function.  ^_^  And to see if it is an injection, you want to investigate whether it is possible for $f(n)=f(n')$ for two different $n,n'\in\mathbb N$.

 The function is, in fact, a bijection.

A: The first thing to do is decode the definition and find out what the function $g$ is doing.
For even $n$:  
$g(0)=0$, $g(2)=1$, $g(4)=2$, $g(6)=3$, $g(8)=4,\dots$ 
So $g$ maps $\{0,2,4,6,8,\dots\}$ bijectively to $\{0,1,2,3,4,\dots\}$.
For odd $n$:
$g(1)=-1$, $g(3)=-2$, $g(5)=-3$, $g(7)=-4$, $g(9)=-5,\dots$
So $g$ maps $\{1,3,5,7,9,\dots\}$ bijectively to $\{-1,-2,-3,-4,-5,\dots\}$.
So the answer is that $g$ is a bijection from $\mathbb N$ to $\mathbb Z$.
Should you feel the need to write this argument more formally, that should be easy to do now that you know what's going on.
P.S. Just for fun, a "non-piecewise" definition of $g(n)$ is
$$g(n)=\frac{(2n+1)\cos n\pi-1}4.$$
