Finding the centralizers of $Q_8$ For $x\in G$, the centraliser in $G$ of $x$ is $C_G(x)=\{g\in G: gx=xg\}$. I'm trying to work out the centralisers in $Q_{8}=\langle a,b:a^4=1,b^2=a^2,ba=a^{-1}b\rangle$.

So to do this I am focusing on one element $x$ at a time comparing $gx$ to $xg$ for all $g$ in the group.

Elements of the group have the form $a^m$ and $a^mb$

So $C_G(1)=\{G\}$

To find $C_G(a):$

$a^ma=a^{m+1}=aa^m$ so hence $a^m$ is in the centraliser

but $a^mba=a^{-1}a^mb$ so $a^mb$ are not in the centraliser, hence $C_G(a)=\{1,a^m\}$

Next to find $C_G(a^2)$:

$a^ma^2=a^{m+2}=a^2a^m$ so hence $a^m$ is in the centraliser

and $a^mba^2=a^{-2}a^mb=a^2a^mb$ so $a^mb$ is in the centraliser = $\{1,a^m,a^mb\}=\{G\}$

For
$C_G(a^3)$ we have the same logic as $C_G(a)$ = $\{1,a^m\}$

Then finally for the elements of the form $a^kb$, nothing commutes with these? so $C_G(a^kb)=\{1\}$

So the center of the group is $\{1,a^2\}$

Is the logic of what I have done correct? Is there a better way of doing it?
First, recall that for a group $G$ and $g \in G$, the centralizer $C_{G}(g)$ is a subgroup of $G$. In the case of finite groups, this is especially helpful, as we can leverage Lagrange's Theorem. Note as well that $\langle g \rangle \leq C_{G}(g)$ (why is this true?).

So a good strategy is to find individual elements that commute with $g$. Once you know $a \in C_{G}(g)$, you immediately have $\langle a \rangle \leq C_{G}(g)$ as well. In this way, you can begin narrowing down candidates based on the lattice of subgroups of $G$.

Similarly, if you can find elements not in $C_{G}(g)$, you can narrow down upper bounds for $|C_{G}(g)|$. Examining the lattice of subgroups of $G$ will also be quite helpful here.
This is basically a question from text of abstract algebra by dummit and foote 4th edition.
Still you have used the definition though langrange's theorem is available to you as discussed by @ ml0150