How does this factoring work? $$ (z^2 - 2i ) = (z -1 -i)(z + 1 +i) $$
I see if you multiply out the right-hand side, you obtain the left-hand side, but how does one know to factor like that or this?
$$ (z^2 − 3iz − 3 + i) = (z − 1 − i)(z + 1 − 2i) $$

The first one
is using
$z^2-a^2
=(z-a)(z+a)
$
where
$a = \sqrt{2i}
=1+i
$
since
$(1+i)^2
=1+2i-1 = 2i
$.
The second one
just uses the quadratic formula,
which works for
complex as well as real coefficients,
to solve
$z^2 − 3iz − 3 + i
= 0
$.
If the roots are
$u$ and $v$,
then
$z^2 − 3iz − 3 + i
= (z-u)(z-v)
$.
(This was added later)
Using the quadratic formula,
the roots are
$\begin{array}\\
\dfrac{3i\pm\sqrt{(-3i)^2-4(-3+i)}}{2}
&=\dfrac{3i\pm\sqrt{-9+12-4i}}{2}\\
&=\dfrac{3i\pm\sqrt{3-4i}}{2}\\
&=\dfrac{3i\pm(2-i)}{2}
\qquad\text{since }\sqrt{3-4i} = 2-i\\
&=\dfrac{3i+(2-i), 3i-(2-i)}{2}\\
&=\dfrac{2+2i, -2+4i}{2}\\
&=1+i, -1+2i\\
\end{array}
$
