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

Computational skills
Computational skillsComputational skills
Computational skills
leoscotch
 
BASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTSBASIC OF ALGORITHM AND MATHEMATICS STUDENTS
BASIC OF ALGORITHM AND MATHEMATICS STUDENTS
jainyshah20
 
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
Meghansh Gautam
 

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

8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
Marwah Studios
 
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
ahafux
 
week 3 questions and answers.phhhhhhhhhhptx
week 3 questions and answers.phhhhhhhhhhptxweek 3 questions and answers.phhhhhhhhhhptx
week 3 questions and answers.phhhhhhhhhhptx
joshuaclack73
 
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdf
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdfTitle Unlocking Imagination The Importance of Toca Boca for Kids.pdf
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdf
Toca boca
 
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjjVector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
joshuaclack73
 

Recently uploaded (20)

Online Winbuzz ID Provider in India | Get Your Sports ID
Online Winbuzz ID Provider in India | Get Your Sports IDOnline Winbuzz ID Provider in India | Get Your Sports ID
Online Winbuzz ID Provider in India | Get Your Sports ID
 
small presentation about Star Wars/.pptx
small presentation about Star Wars/.pptxsmall presentation about Star Wars/.pptx
small presentation about Star Wars/.pptx
 
The Ultimate Guide to Choosing the Best HD IPTV Service in 2024.pdf
The Ultimate Guide to Choosing the Best HD IPTV Service in 2024.pdfThe Ultimate Guide to Choosing the Best HD IPTV Service in 2024.pdf
The Ultimate Guide to Choosing the Best HD IPTV Service in 2024.pdf
 
The Gaming Quiz - 17th April 2024, Quiz Club NITW
The Gaming Quiz - 17th April 2024,  Quiz Club NITWThe Gaming Quiz - 17th April 2024,  Quiz Club NITW
The Gaming Quiz - 17th April 2024, Quiz Club NITW
 
kiff2
kiff2kiff2
kiff2
 
8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
8th Global Fashion and Design Week Noida 2024 Sets New Standards in Creative ...
 
Young & Hot ℂall Girls Visakhapatnam 8250077686 WhatsApp Number Best Rates of...
Young & Hot ℂall Girls Visakhapatnam 8250077686 WhatsApp Number Best Rates of...Young & Hot ℂall Girls Visakhapatnam 8250077686 WhatsApp Number Best Rates of...
Young & Hot ℂall Girls Visakhapatnam 8250077686 WhatsApp Number Best Rates of...
 
NO1 Pakistan kala jadu Specialist Expert in Quetta, Gujranwala, muzaffarabad,...
NO1 Pakistan kala jadu Specialist Expert in Quetta, Gujranwala, muzaffarabad,...NO1 Pakistan kala jadu Specialist Expert in Quetta, Gujranwala, muzaffarabad,...
NO1 Pakistan kala jadu Specialist Expert in Quetta, Gujranwala, muzaffarabad,...
 
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
在线办理(concordia学位证书)康考迪亚大学毕业证学历学位证书学费发票原版一模一样
 
the red riding girl story fkjgoifdjgijogifdoin
the red riding girl story fkjgoifdjgijogifdointhe red riding girl story fkjgoifdjgijogifdoin
the red riding girl story fkjgoifdjgijogifdoin
 
WHO KILLED ALASKA? #17: Mirror Memoria - "OFFICER" TRANSCRIPT.pdf
WHO KILLED ALASKA? #17: Mirror Memoria - "OFFICER" TRANSCRIPT.pdfWHO KILLED ALASKA? #17: Mirror Memoria - "OFFICER" TRANSCRIPT.pdf
WHO KILLED ALASKA? #17: Mirror Memoria - "OFFICER" TRANSCRIPT.pdf
 
C&C Artists' Websites .
C&C Artists' Websites                       .C&C Artists' Websites                       .
C&C Artists' Websites .
 
Vibration Control.pptxjjjjjjjjjjjjjjjjjjjjj
Vibration Control.pptxjjjjjjjjjjjjjjjjjjjjjVibration Control.pptxjjjjjjjjjjjjjjjjjjjjj
Vibration Control.pptxjjjjjjjjjjjjjjjjjjjjj
 
week 3 questions and answers.phhhhhhhhhhptx
week 3 questions and answers.phhhhhhhhhhptxweek 3 questions and answers.phhhhhhhhhhptx
week 3 questions and answers.phhhhhhhhhhptx
 
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdf
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdfTitle Unlocking Imagination The Importance of Toca Boca for Kids.pdf
Title Unlocking Imagination The Importance of Toca Boca for Kids.pdf
 
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdfKhaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
Khaki-Files-Inside-Stories-of-Police-Missions-Kumar-Neeraj-Z-Library.pdf
 
WHO KILLED ALASKA? #15: "5½ STORIES Part Two" Transcript .pdf
WHO KILLED ALASKA? #15: "5½ STORIES Part Two" Transcript .pdfWHO KILLED ALASKA? #15: "5½ STORIES Part Two" Transcript .pdf
WHO KILLED ALASKA? #15: "5½ STORIES Part Two" Transcript .pdf
 
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjjVector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
Vector Methods.pptxjjjjjjjjjjjjjjjjjjjjjj
 
Young & Hot ℂall Girls Jaipur 8250077686 WhatsApp Number Best Rates of Jaipur...
Young & Hot ℂall Girls Jaipur 8250077686 WhatsApp Number Best Rates of Jaipur...Young & Hot ℂall Girls Jaipur 8250077686 WhatsApp Number Best Rates of Jaipur...
Young & Hot ℂall Girls Jaipur 8250077686 WhatsApp Number Best Rates of Jaipur...
 
NO1 Pakistan Vashikaran Specialist in Uk Black Magic Specialist in Uk Black M...
NO1 Pakistan Vashikaran Specialist in Uk Black Magic Specialist in Uk Black M...NO1 Pakistan Vashikaran Specialist in Uk Black Magic Specialist in Uk Black M...
NO1 Pakistan Vashikaran Specialist in Uk Black Magic Specialist in Uk Black M...
 

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.