Let $n \geq 3.$ Show that $Z(D_n) \cong \Bbb Z_2$ if $n$ is even, and $Z(D_n)=\{e\}$ when $n$ is odd.
First, let $n$ be odd. Assume for the contrary that there exists $\sigma \in D_n$ such that $e \neq \sigma$ and $\sigma \tau=\tau \sigma$ for all $\tau \in D_n$, where $e$ denotes the identity in $D_n.$ Since $\sigma \neq e$, there exists $i,j$ positive distinct integers such that $\sigma(i)=j.$ Let $k \neq i,j$ and let $\tau=(i k)$\ (such a $k$ exists since $n \geq 3$). By our assumption, we should have $\sigma \tau=\tau \sigma$, so $$\sigma(\tau(i))=\sigma(k)\neq j=\tau(j)=\tau(\sigma (i))$$ a contradiction, so $\sigma$ must equals $e$. Hence, $Z(D_n)=\{e\}$ i.e the $Z(D_n)$ is trivial, for $n$ odd. I feel i am ok with the part when $n$ is odd, but i am getting stuck when the case $n$ is even. So I would really appreciate any help or thoughts about that.
An alternative proof:
assume that $e \neq g \in Z(D_n)$. Then, $g=a^ib^j$ where $1 \leq i \leq n,\ \ j \in \{0,1\}$, so we have two cases:\ case (i) $g=a^i$. By the assumption that $ g \in Z(D_n)$ and the relation between $a,b$, we have $a^ib=ba^i=a^{-i}b$, therefore $a^i=a^{-i}$ which implies that $e^{2i}=1$. So $e^{2i}=1=e^n$ which means $i=\frac{n}{2}.$\ case(ii) $g=a^ib$. By assumption and the relation between $a,b$,$$a^i=(a^ib)b=b(a^ib)=(ba^i)b=a^{-i}bb=a^{-i}$$ so $a^{i}=a^{-i}$, which implies $i=\frac{n}{2}$. Also, for $a$ we have $$(a^ib)a=a^i(ba)=a^{i-1}b=a(a^ib)=a^{i+1}b$$ i.e $a^{i-1}=a^{i+1}$ here we have $a^2=1$, so what does that mean? and how to show $D_n \cong Z_2$ when $n=2k.$
Thank you.