I was reading about linked list implementation of polynomials. It stated,
Compare this representation with storing the same
polynomial using an array structure.
In the array we have to have keep a slot for each exponent
of x, thus if we have a polynomial of order 50 but containing
just 6 terms, then a large number of entries will be zero in
the array.
I was wondering how do we represent a polynomial in an array? Please guide me.
Thanks
A complete Java implementation of array-based polynomials is here: https://cs.lmu.edu/~ray/classes/dsa/assignment/2/answers/
The basic idea is that if you have a polynomial like
then your array would look like
That is
You can probably see how this represenation would be wasteful for polynomials like
In cases like this you want instead to use a sparse array representation. The simplest approach would be to use a map (dictionary) whose keys are the exponoents and whose values are the coefficients.