What is Polynomials Addition using Linked lists With Example?

In this data Structure Chapter we learn, Polynomials addition, we have taken two polynomials for addition, learn with carefully.

As you know Linked List is widely used for Representing and Manipulating the polynomials. here you will be aware of polynomials, if you are not aware of the polynomials, you will remember that in mathematics you learn polynomials.

therefore polynomials are the expressions that contain the number of terms with non-zero exponents and coefficients.

Consider the following General Represent of Polynomial.
polynomials addition
here, such as the linked representation of polynomials, each term considered as a node, therefore these node contains three fields.

  • Coefficient Field – The coefficient field holds the value of the coefficient of a term
  • Exponent Field – The Exponent field contains the exponent value of the term
  • Link Field – The linked field contains the address of the next term in the polynomial

Let’s see Example | Polynomials Addition

Let us illustrate the way the two polynomials are added, let us consider P and Q be two polynomials having these two polynomials three terms each.
p= 30x2 + 20x + 100x —————(1)
Q= 60x3 + 50x2 + 60x——————(2)
we can represent these two polynomials as:-
Polynomials Addition

Step 1: Compare the exponent of P and the corresponding exponent of q.
here expo(p) < expo(q)
so, added the terms pointer to by q to the resultant list and now advanced the q pointer.
Step 2:
fig-2 graph

first of all, here we compare the exponents of the current items between given P and Q.
expo(p) = expo(q)
therefore, add the coefficients of these two terms and link this to the resultant list and advance the pointers p and q to their next nodes.
Step 3:
Polynomials Addition
furthermore, we compare the exponents of the current terms again
therefore, we add the coefficients of these two terms and link this to the resultant linked list and advance the pointers to their next.
you will notice that nodes Q reaches the NULL and P points the last node.
Step 4:
Polynomials Addition
In the above figure, you will notice that there is no node in the second polynomial to compare with. you can understand in a better way after seeing the figure, so the last node in the first polynomial is added to the end of the resultant linked list. the next below figure is the output which comes Polynomials Addition of two polynomials.
Step 5:
therefore, the display the resultant linked list, the resultant linked list is the pointed to by the pointer.
Polynomials Addition

i.e. R= 60x3 + 80x2 + 80x + 100