SlideShare a Scribd company logo
1 of 9
MULTIPLICATION OF 2
POLYNOMIALS
PRESENTED BY:
AARUL MISHRA (21MCA025)
TARUN GOVER (21MCA008)
INTRODUCTION
Polynomial
A polynomial is an algebraic expression consisting of
variables, coefficients, and operations such as addition,
subtraction, multiplication, and non-negative
exponentiation of variables.
E.g., P(x) = x² − 5x + 9
Linked List
It is a linear data structure that stores data in
nodes at random locations, and the nodes are
connected through pointers.
Now, let's look at the problem statement.
WHAT IS POLYNOMIAL MULTIPLICATION?
Problem Statement
You are given the head pointers two linked lists representing two polynomials, say
head1 and head2. Perform the multiplication of the two polynomials and return the
output as a linked list. The structure of the linked list is provided below.
Now, let's take a look at an example of the multiplication of two polynomials.
Let say we have, P(x) = x² − 5x + 9 and Q(x) = x3 − 10x2 + 9x + 1
We need to find the product P(x)*Q(x).
P(x)*Q(x) = (x² − 5x + 9) * (x3 − 10x2 + 9x + 1)
Every term of P(x) will be multiplied to Q(x) in this way -
P(x)*Q(x) = x² (x3 − 10x2 + 9x + 1) - 5x(x3 − 10x2 + 9x + 1) + 9(x3−10x2+ 9x + 1)
To multiply any two terms, we multiply their coefficients and add up the exponents of
the variable.
So, we get -
P(x)*Q(x) =x5 - 10x4 + 9x3 + x2 - 5x4+50x3 -45x2 - 5x + 9x3 - 90x2 + 81x + 9
=x5 -15x4 +68x3 -134x2 +76x +9
Representation of Polynomials as Linked List
Each node in the linked list denotes one term of the polynomial.
Every node stores -
● Value of exponent
● Value of coefficient
● Pointer to the next node
So, the structure of the node looks like this -
EXAMPLE
Algorithm
1. Define two pointers ptr1 and ptr2, which point to head1 and head2, respectively. These pointers
will be used to iterate over the two lists.
2. Define a new node head3 which points to the head node of the resulting product polynomial.
3. Multiply the terms pointed by ptr1 and ptr2.
4. Declare two variables coefficient and exponent where coefficient = ptr1->coefficient*ptr2-
>coefficient and exponent = ptr1->exponent + ptr2->exponent.
5. Create a new node with the coefficient and exponent found above. And append it to the list
pointed by head3.
6. Update ptr2 to point to the next node in the second polynomial and repeat the above steps till
ptr2 becomes NULL.
7. Similarly, after each complete pass over the second polynomial, reset ptr2 to point to head2
and update ptr1 to point to the next node in the first polynomial.
PICTORIAL REPRESENTATION
Complexity Analysis
Time Complexity
The time complexity for the above-discussed approach is O(n*m), where n is the number of
nodes in the first polynomial and m is the number of nodes in the second polynomial because we
used two nested loops.
Space Complexity
The space complexity for the above approach is O(n+m), we need to store all the multiplied
values in the node.

More Related Content

Similar to MULTIPLICATION OF 2 POLYNOMIALS.pptx

Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationProf Ansari
 
3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphssmiller5
 
Computational skills
Computational skillsComputational skills
Computational skillsleoscotch
 
Relations, functions, and their graphs
Relations, functions, and their graphsRelations, functions, and their graphs
Relations, functions, and their graphsElkin Guillen
 
BASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTSBASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTSjainyshah20
 
Business mathematics presentation
Business mathematics presentationBusiness mathematics presentation
Business mathematics presentationSourov Shaha Suvo
 
Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMeghansh Gautam
 
2d function table
2d function table2d function table
2d function tableD Sanders
 
Class 14 3D HermiteInterpolation.pptx
Class 14 3D HermiteInterpolation.pptxClass 14 3D HermiteInterpolation.pptx
Class 14 3D HermiteInterpolation.pptxMdSiddique20
 
Polynomial Function and Synthetic Division
Polynomial Function and Synthetic DivisionPolynomial Function and Synthetic Division
Polynomial Function and Synthetic DivisionAleczQ1414
 
3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphssmiller5
 
Lecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to InterpolationLecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to InterpolationEric Cochran
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceAravind NC
 
C++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfC++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfMALASADHNANI
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfajajkhan16
 

Similar to MULTIPLICATION OF 2 POLYNOMIALS.pptx (20)

Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs
 
Computational skills
Computational skillsComputational skills
Computational skills
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Relations, functions, and their graphs
Relations, functions, and their graphsRelations, functions, and their graphs
Relations, functions, and their graphs
 
COL106_Assignments.pdf
COL106_Assignments.pdfCOL106_Assignments.pdf
COL106_Assignments.pdf
 
BASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTSBASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTS
 
Business mathematics presentation
Business mathematics presentationBusiness mathematics presentation
Business mathematics presentation
 
Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topic
 
2d function table
2d function table2d function table
2d function table
 
Class 14 3D HermiteInterpolation.pptx
Class 14 3D HermiteInterpolation.pptxClass 14 3D HermiteInterpolation.pptx
Class 14 3D HermiteInterpolation.pptx
 
Python PPT2
Python PPT2Python PPT2
Python PPT2
 
Polynomial Function and Synthetic Division
Polynomial Function and Synthetic DivisionPolynomial Function and Synthetic Division
Polynomial Function and Synthetic Division
 
3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs3.4 Polynomial Functions and Their Graphs
3.4 Polynomial Functions and Their Graphs
 
Lecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to InterpolationLecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to Interpolation
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer Science
 
Excel Homework Help
Excel Homework HelpExcel Homework Help
Excel Homework Help
 
C++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdfC++ Sorting The parameter to the following two recursive routines is.pdf
C++ Sorting The parameter to the following two recursive routines is.pdf
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdf
 
Linked list traversal
Linked list traversalLinked list traversal
Linked list traversal
 

Recently uploaded

VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurVIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurRiya Pathan
 
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...anamikaraghav4
 
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...Riya Pathan
 
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bally - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near MeRiya Pathan
 
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls
 
Call Girls Nashik Gayatri 7001305949 Independent Escort Service Nashik
Call Girls Nashik Gayatri 7001305949 Independent Escort Service NashikCall Girls Nashik Gayatri 7001305949 Independent Escort Service Nashik
Call Girls Nashik Gayatri 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service Gulbarga
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service GulbargaVIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service Gulbarga
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service GulbargaRiya Pathan
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort ServicesApsara Of India
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Riya Pathan
 
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesHi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesApsara Of India
 
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur EscortsVIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service Asansol
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service AsansolVIP Call Girls Asansol Ananya 8250192130 Independent Escort Service Asansol
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service AsansolRiya Pathan
 
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
fmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsfmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsa18205752
 
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...Riya Pathan
 
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...srsj9000
 
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969Beyond Bar & Club Udaipur CaLL GiRLS 09602870969
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969Apsara Of India
 
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICE
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICEGV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICE
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICEApsara Of India
 
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSHot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSApsara Of India
 

Recently uploaded (20)

VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurVIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
 
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
 
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...
Verified Call Girls Esplanade - [ Cash on Delivery ] Contact 8250192130 Escor...
 
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...
Private Call Girls Durgapur - 8250192130 Escorts Service with Real Photos and...
 
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near MePrivate Call Girls Bally - 8250192130 | 24x7 Service Available Near Me
Private Call Girls Bally - 8250192130 | 24x7 Service Available Near Me
 
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.comKolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
Kolkata Call Girls Service +918240919228 - Kolkatanightgirls.com
 
Call Girls Nashik Gayatri 7001305949 Independent Escort Service Nashik
Call Girls Nashik Gayatri 7001305949 Independent Escort Service NashikCall Girls Nashik Gayatri 7001305949 Independent Escort Service Nashik
Call Girls Nashik Gayatri 7001305949 Independent Escort Service Nashik
 
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service Gulbarga
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service GulbargaVIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service Gulbarga
VIP Call Girls in Gulbarga Aarohi 8250192130 Independent Escort Service Gulbarga
 
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
5* Hotel Call Girls In Goa 7028418221 Call Girls In North Goa Escort Services
 
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Bagbazar 👉 8250192130 ❣️💯 Available With Room 24×7
 
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort ServicesHi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
Hi Class Call Girls In Goa 7028418221 Call Girls In Anjuna Beach Escort Services
 
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur EscortsVIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service Asansol
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service AsansolVIP Call Girls Asansol Ananya 8250192130 Independent Escort Service Asansol
VIP Call Girls Asansol Ananya 8250192130 Independent Escort Service Asansol
 
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
fmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the heartsfmovies-Movies hold a special place in the hearts
fmovies-Movies hold a special place in the hearts
 
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
 
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...
Hifi Laxmi Nagar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ D...
 
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969Beyond Bar & Club Udaipur CaLL GiRLS 09602870969
Beyond Bar & Club Udaipur CaLL GiRLS 09602870969
 
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICE
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICEGV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICE
GV'S 24 CLUB & BAR CONTACT 09602870969 CALL GIRLS IN UDAIPUR ESCORT SERVICE
 
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtSHot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
Hot Call Girls In Goa 7028418221 Call Girls In Vagator Beach EsCoRtS
 

MULTIPLICATION OF 2 POLYNOMIALS.pptx

  • 1. MULTIPLICATION OF 2 POLYNOMIALS PRESENTED BY: AARUL MISHRA (21MCA025) TARUN GOVER (21MCA008)
  • 2. INTRODUCTION Polynomial A polynomial is an algebraic expression consisting of variables, coefficients, and operations such as addition, subtraction, multiplication, and non-negative exponentiation of variables. E.g., P(x) = x² − 5x + 9
  • 3. Linked List It is a linear data structure that stores data in nodes at random locations, and the nodes are connected through pointers. Now, let's look at the problem statement.
  • 4. WHAT IS POLYNOMIAL MULTIPLICATION? Problem Statement You are given the head pointers two linked lists representing two polynomials, say head1 and head2. Perform the multiplication of the two polynomials and return the output as a linked list. The structure of the linked list is provided below. Now, let's take a look at an example of the multiplication of two polynomials. Let say we have, P(x) = x² − 5x + 9 and Q(x) = x3 − 10x2 + 9x + 1 We need to find the product P(x)*Q(x). P(x)*Q(x) = (x² − 5x + 9) * (x3 − 10x2 + 9x + 1) Every term of P(x) will be multiplied to Q(x) in this way - P(x)*Q(x) = x² (x3 − 10x2 + 9x + 1) - 5x(x3 − 10x2 + 9x + 1) + 9(x3−10x2+ 9x + 1) To multiply any two terms, we multiply their coefficients and add up the exponents of the variable. So, we get - P(x)*Q(x) =x5 - 10x4 + 9x3 + x2 - 5x4+50x3 -45x2 - 5x + 9x3 - 90x2 + 81x + 9 =x5 -15x4 +68x3 -134x2 +76x +9
  • 5. Representation of Polynomials as Linked List Each node in the linked list denotes one term of the polynomial. Every node stores - ● Value of exponent ● Value of coefficient ● Pointer to the next node So, the structure of the node looks like this -
  • 7. Algorithm 1. Define two pointers ptr1 and ptr2, which point to head1 and head2, respectively. These pointers will be used to iterate over the two lists. 2. Define a new node head3 which points to the head node of the resulting product polynomial. 3. Multiply the terms pointed by ptr1 and ptr2. 4. Declare two variables coefficient and exponent where coefficient = ptr1->coefficient*ptr2- >coefficient and exponent = ptr1->exponent + ptr2->exponent. 5. Create a new node with the coefficient and exponent found above. And append it to the list pointed by head3. 6. Update ptr2 to point to the next node in the second polynomial and repeat the above steps till ptr2 becomes NULL. 7. Similarly, after each complete pass over the second polynomial, reset ptr2 to point to head2 and update ptr1 to point to the next node in the first polynomial.
  • 9. Complexity Analysis Time Complexity The time complexity for the above-discussed approach is O(n*m), where n is the number of nodes in the first polynomial and m is the number of nodes in the second polynomial because we used two nested loops. Space Complexity The space complexity for the above approach is O(n+m), we need to store all the multiplied values in the node.