Solution (source code)

= Solution

Write $A=g_1$, $B=g_2$ and $C=AB$. Direct multiplication gives
$$
A^2=B^2=I_2,\qquad BA=-AB,\qquad
C=\begin{pmatrix}0&1\\-1&0\end{pmatrix},\qquad C^2=-I_2.
$$
The relation $BA=-AB$ moves all occurrences of $A$ to the left of all occurrences of $B$. Removing even powers reduces every product of the generators to $\pm A^aB^b$ with $a,b\in\{0,1\}$. The resulting eight <matrices> are distinct, so
$$
\boxed{G=\{\pm I_2,\ \pm A,\ \pm B,\ \pm C\},\qquad |G|=8.}
$$
Explicitly, the four pairs are
$$
\pm\begin{pmatrix}1&0\\0&1\end{pmatrix},\quad
\pm\begin{pmatrix}1&0\\0&-1\end{pmatrix},\quad
\pm\begin{pmatrix}0&1\\1&0\end{pmatrix},\quad
\pm\begin{pmatrix}0&1\\-1&0\end{pmatrix}.
$$
Since $AB=-BA$ and $AB\ne0$, the <group> is noncommutative. More precisely, $C$ has order four, $A$ has order two and $ACA=C^{-1}$, identifying $G$ with the <dihedral group> of a square. This fixes the convention unambiguously: it is the <dihedral group> of <group order> eight, irrespective of whether it is denoted $D_4$ or $D_8$.