Write an algorithm to add two polynomials.

To add two polynomials, examine their terms starting at the nodes pointed to by a and b.

  • If the exponents of the two terms are equal, then add the two coefficients and create a new term for the result, and also move the pointers to the next nodes in a and b.
  • If the exponent of the current term in a is less than the exponent of the current term in b, then create a duplicate term of b, attach this term to the result, called c, and advance the pointer to the next term in b.
  • If the exponent of the current term in b is less than the exponent of the current term in a, then create a duplicate term of a, attach this term to the result, called c, and advance the pointer to the next term in a

Below figure illustrates this process for the polynomials addition.

Leave a Reply

Your email address will not be published. Required fields are marked *