Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Polynomial of a variable can be represented as an ordered list of terms and the

ID: 3913816 • Letter: P

Question

Polynomial of a variable can be represented as an ordered list of terms and the terms are ordered by their exponents. In order to add polynomials, traverse both the lists to examine the two terms at the current iterator position. If the exponent of one is smaller than the other then that should be inserted into the result and advance that list iterator. For example:

if 4x^3 + 3x^2 + 6 is added to 4x^4 + 3x^2 + 2x + 5 should result as: 4x^4 + 4x^3 + 6x^2 + 2x +11

And if the exponents are equal then create a new term with the exponent and the sum of the coefficients and advance both the iterators as shown above.

I want to write a program using linked list to add polynomials and want to define a class Term that contains the exponent and coefficient and implements the interface Comparable. I want to define a class Polynomial that uses a util.LinkedList to hold its terms and then provide toString method to print out the polynomial. I don’t want to read input from the keyboard but just use the methods to construct the polynomials. Few conditions to do are:

There is only one representation of zero. The polynomials are in order of exponent and if two terms cancel out then zero term should not be included unless the entire polynomial is zero.

Explanation / Answer

Hi,

Below are the required classes Term.java and Polynomial.java. Polynomial class contains main method where I have created two polynomials(You can change the data in that) and added them to create third polynomial using the add() mwthod of polynomial class.

Term.java

Polynomial.java

Output: 4x^4 + 4x^3 + 6x^2 + 2x + 11