Consider the algorithm below, which prints the roots of the cubic polynomial \(f(x)=x^3-2 x^2-9 x+18\).
\begin{array} {l}
\rule{0pt}{2.5ex} \textbf{ define} \ \text{ f (x) } \\
\rule{0pt}{2.5ex} \quad \quad \textbf{return} \ \text{(x} ^3 - 2 \text{x}^2 - 9 \text{x} + 18) \\
\rule{0pt}{2.5ex} \text{c} \leftarrow \text{f} \ (0) \\
\rule{0pt}{2.5ex} \textbf{if}\ \ \text{c < 0} \ \textbf{then}\\
\rule{0pt}{2.5ex} \quad \quad \text{c} \ \leftarrow \ \text{(- c)} \\
\rule{0pt}{2.5ex} \textbf{end if} \\
\rule{0pt}{2.5ex} \textbf{while} \ \text{ c > 0 } \\
\rule{0pt}{2.5ex} \quad \quad \textbf{if} \ \ \text{f (c) = 0 } \ \textbf{then} \\
\rule{0pt}{2.5ex} \quad \quad \quad \quad \textbf{print} \ \text{c } \\
\rule{0pt}{2.5ex} \quad \quad \textbf{end if} \\
\rule{0pt}{2.5ex} \quad \quad \textbf{if} \ \ \text{f (-c) = 0} \ \textbf{then} \\
\rule{0pt}{2.5ex} \quad \quad \quad \quad \textbf{print} \ \text{-c } \\
\rule{0pt}{2.5ex} \quad \quad \textbf{end if} \\
\rule{0pt}{2.5ex} \quad \quad \text{c} \ \leftarrow \ \text{c - 1} \\
\rule{0pt}{2.5ex} \textbf{ end while } \\
\end{array}
In order, the algorithm prints the values
- \(-3, 3, 2\)
- \(-3, 2, 3\)
- \(3, 2, -3\)
- \(3, -3, 2\)