Answer
a. $P(x)=(x-2)(x^2+x+2)$,
b. $P(x)=(x-2)\left(x+\frac{1-\sqrt {7}i}{2}\right)\left(x+\frac{1+\sqrt {7}i}{2}\right)$
Work Step by Step
a) Factor $P$ into linear and irreducible quadratic factors:
See The Rational Zero Theorem:
If $\frac{p}{q}$ is a zero of the polynomial $f$ with integer coefficients, then $p$ is a factor of the constant term, $a_{0}$, and $q$ is a factor of the leading coefficient, $a_{n}$.
------------------------
$P(x)=x^3-2x-4$
Candidates for zeros, $\frac{p}{q}:$
$p:\qquad \pm 1,\pm2,\pm4$
$q:\qquad \pm 1$
$\displaystyle \frac{p}{q}:\qquad\pm 1, \pm2,\pm4$
Try for $x=2$.
$\begin{array}{lllll}
\underline {2}| & 1& 0 & -2& -4\\
& & 2 & 4&4\\
& -- & -- & -- & --\\
& 1& 2& 2 & |\underline{0}
\end{array}$
$2$ is a zero,
$P(x)=(x-2)(x^2+x+2)$,
b) Factor $P$ completely into linear factors:
Solve $x^2+x+2=0$:
$x=\frac{-1\pm\sqrt 7i}{2}$
The polynomial $P$ can be written:
$P(x)=(x-2)\left(x+\frac{1-\sqrt {7}i}{2}\right)\left(x+\frac{1+\sqrt {7}i}{2}\right)$