Given $f(x)= \left\{ \begin{array}{1 1} n-1 & \quad if\;n\;is\;odd \\ n+1 & \quad if\;n\;is\;even \end{array} \right. $

To check if a function is invertible or not ,we see if the function is both one-one and onto.

$\textbf {Step 1: Checking one-one}$

$\textit{Case 1: Consider the case where n is odd, m is even}$

Let $f(n) = f(m) \Rightarrow n - 1 = m+1 \rightarrow n-m = 2$

Difference of an even number and odd number cannot be 2

Therefore, $n - m \neq 2$. Similarly, m being odd and n being even can also be discarded with a similar argument.

$\textit{Case 2: Consider the case where n and m are odd}$

Let $f(n) = f(m) \Rightarrow n - 1 = m -1 \rightarrow n=m$

$\textit{Case 3: Consider the case where n and m are even}$

Let $f(n) = f(m) \Rightarrow n - 1 = m -1 \rightarrow n=m$

Therefore, we see that $f$ is one-one for the case where $n=m$ for both odd and even cases.

$\textbf {Step 2: Checking onto}$

For any odd number $2r+1$ in codomain $W$ then is an image $2r$ in $W$, and similarly, for any even number $2r$ in codomain $W$ there is an image $2r+1$ in $W$ also $\rightarrow f\;$ is onto..

Given that $f$ is both one-one and onto, $f$ is invertible.

$\textbf {Step 3: To calculate}\; f^{-1}, \textbf {we must first define g(y):}$

We know that a function $g$ is called inverse of $f:x \to y$, then exists $g:y \to x$ such that $ gof=I_x\;and\; fog=I_y$, where $I_x, I_y$ are identify functions.

Let us define a function $g(x)= \left\{ \begin{array}{1 1} m+1 & \quad if\;m\;is\;even \\ m-1 & \quad if\;m\;is\;odd \end{array} \right. $

$\textbf {Step 4: Calculate gof}$

If n is odd then n-1 is even number, and when n is even, n+1 is odd.

When $n$ is odd $\Rightarrow$ $gof(n)=g(f(n))=g(n-1) = n-1+1=n$

When $n$ is even $\Rightarrow$ $gof(n)=g(f(x))=g(n+1)=n+1-1=n$

Thus $gof = I_W$

$\textbf {Step 5: Calculate fog}$

If m is odd then m-1 is even number, and when m is even, m+1 is odd.

When $m$ is odd $\Rightarrow$ $fog(m) = f(g(m)) =f(m-1) = m-1+1=m$

When $m$ is even $\Rightarrow$ $fog(m)=f(g(x))=f(m+1)=f+1-1=m$

Thus $fog = I_W$

$\textbf {Step 6: Calculating} \; f^{-} \textbf{ from} \; gof = fog$:

Since $gof = I_W = fog$, the inverse $f^{-1} = g$ which is nothing but $f$ itself.