nextupprevious
Next:PostfixInfix and Prefix Up:Assignment 2Previous:Assignment 2

The polynomial ADT(12 points)

Implementation of the ADT polynomial(9 points)

Given the polynomial ADT(see below), write the routines required to perform the different operations in the two following cases:
  1. An array is used to store the different coefficients of the polynomial. The size of the array is equal the degree+1 where degree is the degree of the polynomial, e.g. :
  2. A singly linked list is used to store the different terms of the polynomial: pairs tex2html_wrap_inline85 representing the non negative coefficients and their corresponding exponent, e.g. the singly linked list representation of the example above is:
Structure Polynomial is
Data:tex2html_wrap_inline87 : a set of sorted pairs tex2html_wrap_inline89 .

tex2html_wrap_inline91

Functions:

for every poly, poly1, poly2 tex2html_wrap_inline93 Polynomial, coef tex2html_wrap_inline93 Coefficient, expon tex2html_wrap_inline93 Exponents

Polynomial Zero() ::= return the polynomial p(x)=0

Boolean isZero(poly) ::= return (poly == 0)

Coefficient Coeff(poly , expon) ::= If (expon tex2html_wrap_inline93 poly) return its corresponding coefficient else return 0

Exponent LeadExp(poly) ::= return the degree of poly

Polynomial Remove(poly , expon) ::= If (expon tex2html_wrap_inline93 poly) remove the corresponding term  and return the new poly  else return ERROR

Polynomial SingleMult(poly , coef , expon) ::= return poly tex2html_wrap_inline105 coef x tex2html_wrap_inline107

Polynomial Add(poly1 , poly2) ::= return poly1 + poly2

Polynomial Mult(poly1 , poly2) ::= return poly1 tex2html_wrap_inline105 poly2

end Polynomial

Experimental study of the two representations(3 points)

While time complexities of the different routines in the case of array representation are comparable to those of linked list representation, for non dense polynomials, where most terms of the polynomial are not present, the running time of the multiplication is very slow and sometimes unacceptable in the case of array representation.
Using the following parameter, compare the running time required by the multiplication in both kind of representation:

displaymath113
 


Malek Mouhoub

Friday February 4 19:04:44 MST 2000