Inverting this function I have to invert this function: $$f: \mathbb{N} \rightarrow \mathbb{N}, f(n) =
\begin{cases}
n+1,  & \text{if $n$ is odd} \\
n-1, & \text{if $n$ is even}
\end{cases}$$
But I am not able to grasp how to invert it while also handling the conditions set on the function. Can any one please give me the steps for inverting such type of functions? These have suddenly appeared in my textbook and they haven't explained how to solve it either :(
Update: I know the answer, which I got by checking values. But I want a formal approach to get the inverse of this function, and other such functions in general.
 A: It seems $f^{-1}(n) = f(n)$, because $f$ sends all odd numbers to an even number that is greater by $1$ (so an even number), and all even numbers get sent to a number that is smaller by $1$ (an odd number). Reverse this process and you get the exact same function again.
What you do is basically swapping each pair:
$$\begin{align}
1 \mapsto 2\\
2 \mapsto 1\\
\\
3\mapsto 4\\
4\mapsto 3\\
\\
5\mapsto 6\\
6\mapsto 5\\
\vdots
\end{align}$$
For solving questions like those in general: Try to plot your function (if the domain is real) or write out what happens to the first few $n\in\mathbb N$ in order to get an idea. But other than that you can also try to reverse a process: given an $m$, can you find an $n$ such that $f(n)=m$?
In this case we have to look at both cases: What if $m$ is even and what if it is odd? 
Let us consider the case if $m$ is even, then there should be an $n$ such that $n+1=m$ or $n-1=m$ depending on whether $n$ was even. And you see that both in both of the cases $n=m-1$ and $n=m+1$ $n$ will be odd. But in this case we know that $n+1=m$, etc etc. 
But other than those hints I do not think that there is a more general approach. For many (real) functions there are no elemenatry inverses and for sequences I think it might be a difficult problem too.
