Assume $D_{2n}= \langle a,b \mid a^n = 1 = b^2, b^{-1}ab = a^{-1}\rangle$ has this presentation. $D_{2n}\neq\emptyset$ since $1\in D_{2n}$. Let $a,b\in D_{2n}$ such that $a\neq b$, $a,b\neq1$ else this presentation is futile.
$\textit{Claim}$: $|a|=n$ and $|b|=2$.
$b^2=1.$ Then $ |b|\:\Bigg|\:2$. Since $b\neq1\implies |b|=2$.
$a^n=1.$ Then $ |a|\:\Bigg|\:n$. Let $|a|=k,\;k<n$.
By Euclid's algorithm, $\exists!\; q,r\in\mathbb{Z}\;:\;n=kq+r$ with $0\leq r<n$.
$$a^n=a^{kq+r}\implies a^r=1\Rightarrow\Leftarrow |a|=k$$ Hence the claim.
$D_{2n}=\langle a,b\rangle$, every element of $D_{2n}$ has the form $a^ib^j,\;i\in\{0,1,\cdots,(n-1)\} \;\text{and}\;j\in\{0,1\}$.
We prove that the set has distinct elements for all $(i,j)$.
Using $bab=a^{-1}$, we can derive
- $a^kba^{k}=b$,
- $ba^kb=a^{-k}\quad$ and subsequently
- $b^ma^kb^m=a^{((-1)^mk)}$.
We shall also use the fact : $\langle a\rangle \cap \langle b\rangle=\{1\}\tag1$
Suppose $$a^ib^j =a^mb^k\tag2$$ where $i\neq m \;\text{where}\;i,m\in\{0,1,\cdots,(n-1)\},\;j\neq k\;\text{where}\;j,k\in\{0,1\}$. Without loss of generality let $m>i$, from $(2)$ we have the following:
$$\begin{align}a^ib^ja^i =a^mb^ka^i &\implies b^j=a^{m-i}b^k\\ &\implies b^kb^j=b^ka^{((-1)^k(m-i))}b^k=a^{((-1)^k(m-i))}\end{align}$$
i.e. $$b^{k+j}=a^{((-1)^k(m-i))}\tag3$$ Thus, $b^{k+j},a^{((-1)^k(m-i))}=1$. $\; b^{k+j}=1\implies \;k+j\:\Bigg|\:2$. So $k+j=1$ or $2$. $k+j\neq2$ as $j\neq k$ and $j,k\in\{0,1\}$. So $j+k=1$.
$(3)\implies b=a^{((-1)^k(m-i))}\Rightarrow\Leftarrow$ as $b\notin \langle a\rangle$.
For the case in $(2)$ where $i=m$ but $j\neq k$, $$a^ib^j =a^mb^k\implies b^j=b^k\iff j=k$$
For the case in $(2)$ where $i\neq m$ but $j= k$, $$a^ib^j =a^mb^k\implies a^{m-i}=1\;\text{with}\; (m-i)<n \Rightarrow\Leftarrow\;\text{ as}\; |a|=n$$
Since we have shown that $a^ib^j$ is distinct for all $(i,j)$, by simple combinatorics we see that $|D_{2n}|=2n$
Proof for $(1)$ :
For suppose $\langle a\rangle \cap \langle b\rangle\neq\{1\}$ then $b\in\langle a\rangle$. If $n$ is odd then, $|b|\not\Bigg|\;n$ giving us a contradiction. If $n$ is even, then $\langle a\rangle$ has two elements of order $2$ namely $b$ and $a^{n/2}$. But this will also contradict the fact that "If $G$ is a group of even order then the number of elements of $G$ of order $2$ is odd."
Hence the fact $\langle a\rangle \cap \langle b\rangle=\{1\}$.