next up previous
Next: Evaluating a polynomial Up: Description Previous: Adding polynomials


Multiplying polynomials

Suppose you'd like to multiply the two polynomials of the previous subsection: $ a_n x^n$ $ +$ $ \cdots$ $ +$ $ a_1 x$ $ +$ $ a_0$, and $ b_m x^m$ $ +$ $ \cdots$ $ +$ $ b_1 x$ $ +$ $ b_0$. Their product has degree $ k$ $ =$ $ m+n$:

$\displaystyle c_{m+n} x^{m+n} + \cdots + c_1 x + c_0
$

...where $ c_i$ $ =$ $ a_0 b_i$ $ +$ $ a_1 b_{i-1}$ $ +$ $ \cdots$ $ +$ $ a_i b_0$, where $ a_j$ is zero unless 0 $ \leq$ $ j$ $ \leq$ $ n$, and similarly $ b_j$ is zero unless 0 $ \leq$ $ j$ $ \leq$ $ m$.

A special case occurs when either polynomial is the zero polynomial. In that case, the product is the zero polynomial.

Implement the function mult specified in Polynomial.h. You need to be sure that none of your coefficients, or intermediate calculations, fall outside $ \pm$INT_MAX, specified in <limits.h> (in which case you should return {NULL, OVERFLOW}). For polynomials of degree $ n$ and $ m$ (assuming that $ n$ $ \geq$ $ m$), your function should have complexity $ O(n^2)$.



Danny Heap 2002-09-20