next up previous
Next: Multiplying polynomials Up: Description Previous: Description


Adding polynomials

Suppose you'd like to add two polynomials: $ a_n x^n$ $ +$ $ \cdots$ $ +$ $ a_1 x$ $ +$ $ a_0$, and $ b_m x^m$ $ +$ $ \cdots$ $ +$ $ b_1 x$ $ +$ $ b_0$. Their sum has degree $ k$ $ =$ $ \max(m,n)$:

$\displaystyle c^k x^k + \cdots + c_1 x + c_0
$

...where $ c_i$ $ =$ $ a_i+b_i$ ($ a_i$ is zero if $ i>n$, and $ b_i$ is zero if $ i>m$).

Implement the function plus specified in Polynomial.h. You need to check that none of your coefficients fall outside $ \pm$INT_MAX, specified in <limits.h> (in which case you should return {NULL, OVERFLOW}). For a polynomial of degree $ n$, your function should have complexity $ O(n)$.



Danny Heap 2002-09-20