SlideShare a Scribd company logo
1 of 18
Divide-and-Conquer
Multiply two polynomials
Presentation by
Hasanain ALshadoodee
Multiply two polynomials
Presentation by_Hasanain ALshadoodee
3
Introduction
 Multiplying Polynomials
To multiply two polynomials together, multiply every term
of one polynomial by every term of the other polynomial.
Divide-and-Conquer
Multiply two polynomials
 Problem
Given two polynomials represented by two arrays, write a function that
multiplies given two polynomials.
Input: A[] = {10, 5, 11}
B[] = {3, 2, 1}
Output: prod C[] = 10 X + 5 x1 + 11 x2
3 X + 2 x1 + 1 x2
= 30 + 10 * 2x1 + 10 * 1x1 + 5x1 * 3+ 5x1 * 2x1 + 5x1 * 1x2 + 11x2 * 3 +
11x2 * 2x1 + 11x2 * 1x2
polynomials
Presentation by_Hasanain ALshadoodee
4
Naïve Method
One by one consider every term of first polynomial
and multiply it with every term of second polynomial
this will take O(n2) time complexity .
Presentation by_Hasanain ALshadoodee
5
Algoritham
1) Create a product array prod[] of size m+n-1.
2) Initialize all entries in prod[] as 0.
3) Traverse array A[] and do following for every element A[i]
Traverse array B[] and do following for every element B[j]
so prod[i+j] = prod[i+j] + A[i] * B[j]
4) Return prod[].
Presentation by_Hasanain ALshadoodee
6
Analysis of Naïve Method
 Time complexity of the above solution is O(mn).
 If size of two polynomials same, then time complexity is
O(n2).
There are method to do multiplication faster that O(n2)
time.
This is method are based on Divide and conquer technique
.
Presentation by_Hasanain ALshadoodee
7
Divide and Conquer Method
Presentation by_Hasanain ALshadoodee
8
Let the two given polynomials be A and B.
For simplicity, Let us assume that the given two
polynomials are of
same degree and have degree in powers of 2,
i.e., n = 2i
* polynomial 'A' can be written as A0 + A1* xn/2
* polynomial 'B' can be written as B0 + B1* xn/2
Presentation by_Hasanain ALshadoodee
Example
polynomial A=2 + 3x + 6x2 - 2x3 + 5x4
polynomial B=1 - 6x + 7x2 + 2x3 + 8x4
Polynomial A=(2 + 3x) + (6 - 2x + 5x2 ) x2
A0 A1
polynomial B=(1 - 6x) + (7 + 2x + 8x2 ) x2
B0 B1
A * B = (A0 + A1*xn/2) * (B0 + B1*xn/2)
= A0*B0 + A0*B1*xn/2 + A1*B0*xn/2 + A1*B1*xn
= A0*B0 + (A0*B1 + A1*B0)xn/2 + A1*B1*xn
Example
 IN the example we can see divide and conquer method
requires 4 multiplication and O(n) time to add all 4
results .
T(n)=4T(n/2) + O(n)
The solution of recurrence is O(n2) .
But it can be reduced .
T(n)=3T(n/2) + O(n)
Using stressing matrix multiplication .
Presentation by_Hasanain ALshadoodee
10
Programming and Data Structures
Presentation by_Hasanain ALshadoodee
11
 Consider the following polynomials
Each term of the polynomial 1 must be multiplied
with each term of the polynomial
Multiplying each term means multiplying their coefficients
and adding their
1
2
Consider the following polynomials
Presentation by_Hasanain ALshadoodee
12
Resultant polynomial
Consider the following polynomials
Presentation by_Hasanain ALshadoodee
13
head1
head2
ptr2
ptr1
We need pointers (ptr1 and otr2) for traversal , so we also need a
nested loop as each term of the first polynomial must be multiplied
with every term of second polynomial.
Consider the following polynomials
Presentation by_Hasanain ALshadoodee
14
head1
head2
ptr2
ptr1
While (ptr1 != NULL)
 While (ptr2 != NULL)



Consider the following polynomials
Presentation by_Hasanain ALshadoodee
15
head1
head2
head3
Int res1 , res2 ;
Struct node * head3=NULL;
While (ptr1 != NULL)
 Ptr2=head2;
While (ptr2 != NULL)


 ptr1=ptr1-> link;
Presentation by_Hasanain ALshadoodee
16
Consider the following polynomials
Resultant
polynomial
We will get this polynomial of term executing the
cod be causes of insert function
References
 Section 5.6 of the text book “algorithm design” by Jon Kleinberg and Eva
Tardos.
 The original slides were prepared by Kevin Wayne. The slides are
distributed by Pearson Addison-Wesley.
 Wireless Algorithms, Systems, and Applications: 9th International
Conference .
 Crack GATE & ESE with Unacademy : Divide and Conquer: Multiply 2
Polynomials.
 Important Links
• Submit your work here: https://jovian.ai/learn/data-structures-and-algorithms-in-python/assignment/assignment-3-
sorting-and-divide-conquer-practice
• Ask questions and get help: https://jovian.ai/forum/c/data-structures-and-algorithms-in-python/assignment-3/89
• Lesson 3 video for review: https://jovian.ai/learn/data-structures-and-algorithms-in-python/lesson/lesson-3-sorting-
algorithms-and-divide-and-conquer
• Lesson 3 notebook for review: https://jovian.ai/aakashns/python-sorting-divide-and-conquer
• Algebra I #5.11, Multiply two Polynomials https://www.youtube.com/watch?v=VAELGq-FViY
• Application of Linked List (Multiplication of Two Polynomials) https://www.youtube.com/hashtag/linkedlist
Presentation by_Hasanain ALshadoodee
17
Presentation by_HasanainALshadoodee 18

More Related Content

What's hot

Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Rai University
 
Some Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial DerivativesSome Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial DerivativesSanjaySingh011996
 
properties of multiplication of integers
properties of multiplication of integersproperties of multiplication of integers
properties of multiplication of integerssufiyafatima
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15Hira Gul
 
The Application of Derivatives
The Application of DerivativesThe Application of Derivatives
The Application of Derivativesdivaprincess09
 
Btech_II_ engineering mathematics_unit2
Btech_II_ engineering mathematics_unit2Btech_II_ engineering mathematics_unit2
Btech_II_ engineering mathematics_unit2Rai University
 
21 monotone sequences x
21 monotone sequences x21 monotone sequences x
21 monotone sequences xmath266
 
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES   PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES Mazharul Islam
 
11.1 linear equations in two variables
11.1 linear equations in two variables11.1 linear equations in two variables
11.1 linear equations in two variablesGlenSchlee
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relationsIIUM
 
Composite Functions.ppt
Composite Functions.pptComposite Functions.ppt
Composite Functions.pptXiaodong Li
 
1.1 Linear Equations
1.1 Linear Equations1.1 Linear Equations
1.1 Linear Equationssmiller5
 
complex numbers
complex numberscomplex numbers
complex numbersvalour
 
Newton's forward difference
Newton's forward differenceNewton's forward difference
Newton's forward differenceRaj Parekh
 

What's hot (20)

Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3Btech_II_ engineering mathematics_unit3
Btech_II_ engineering mathematics_unit3
 
246242769 sequence-1-pdf
246242769 sequence-1-pdf246242769 sequence-1-pdf
246242769 sequence-1-pdf
 
Some Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial DerivativesSome Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial Derivatives
 
properties of multiplication of integers
properties of multiplication of integersproperties of multiplication of integers
properties of multiplication of integers
 
Generating function
Generating functionGenerating function
Generating function
 
08 decrease and conquer spring 15
08 decrease and conquer spring 1508 decrease and conquer spring 15
08 decrease and conquer spring 15
 
The Application of Derivatives
The Application of DerivativesThe Application of Derivatives
The Application of Derivatives
 
Btech_II_ engineering mathematics_unit2
Btech_II_ engineering mathematics_unit2Btech_II_ engineering mathematics_unit2
Btech_II_ engineering mathematics_unit2
 
21 monotone sequences x
21 monotone sequences x21 monotone sequences x
21 monotone sequences x
 
4-The Simplex Method.ppt
4-The Simplex Method.ppt4-The Simplex Method.ppt
4-The Simplex Method.ppt
 
Roll's theorem
Roll's theoremRoll's theorem
Roll's theorem
 
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES   PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES
PRESENTATION ON INTRODUCTION TO SEVERAL VARIABLES AND PARTIAL DERIVATIVES
 
11.1 linear equations in two variables
11.1 linear equations in two variables11.1 linear equations in two variables
11.1 linear equations in two variables
 
Application of derivative
Application of derivativeApplication of derivative
Application of derivative
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
 
Differential equations
Differential equationsDifferential equations
Differential equations
 
Composite Functions.ppt
Composite Functions.pptComposite Functions.ppt
Composite Functions.ppt
 
1.1 Linear Equations
1.1 Linear Equations1.1 Linear Equations
1.1 Linear Equations
 
complex numbers
complex numberscomplex numbers
complex numbers
 
Newton's forward difference
Newton's forward differenceNewton's forward difference
Newton's forward difference
 

Similar to Divide and-conquer multiply two polynomials

Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms IiSri Prasanna
 
Prin digcommselectedsoln
Prin digcommselectedsolnPrin digcommselectedsoln
Prin digcommselectedsolnAhmed Alshomi
 
Answers To Exercises Microeconomic Analysis Third Edition
Answers To Exercises Microeconomic Analysis Third EditionAnswers To Exercises Microeconomic Analysis Third Edition
Answers To Exercises Microeconomic Analysis Third EditionStephen Faucher
 
Proof of Kraft Mc-Millan theorem - nguyen vu hung
Proof of Kraft Mc-Millan theorem - nguyen vu hungProof of Kraft Mc-Millan theorem - nguyen vu hung
Proof of Kraft Mc-Millan theorem - nguyen vu hungVu Hung Nguyen
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.pptjvjfvvoa
 
Introduction to probability solutions manual
Introduction to probability   solutions manualIntroduction to probability   solutions manual
Introduction to probability solutions manualKibria Prangon
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theoremitutor
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...ssuserd6b1fd
 
Scilab help book 2 of 2
Scilab help book 2 of 2Scilab help book 2 of 2
Scilab help book 2 of 2Arun Umrao
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fittingAmeen San
 
The 2 Goldbach's Conjectures with Proof
The 2 Goldbach's Conjectures with Proof The 2 Goldbach's Conjectures with Proof
The 2 Goldbach's Conjectures with Proof nikos mantzakouras
 

Similar to Divide and-conquer multiply two polynomials (20)

Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Prin digcommselectedsoln
Prin digcommselectedsolnPrin digcommselectedsoln
Prin digcommselectedsoln
 
Answers To Exercises Microeconomic Analysis Third Edition
Answers To Exercises Microeconomic Analysis Third EditionAnswers To Exercises Microeconomic Analysis Third Edition
Answers To Exercises Microeconomic Analysis Third Edition
 
Complex%20numbers
Complex%20numbersComplex%20numbers
Complex%20numbers
 
Calc 2.2a
Calc 2.2aCalc 2.2a
Calc 2.2a
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Proof of Kraft Mc-Millan theorem - nguyen vu hung
Proof of Kraft Mc-Millan theorem - nguyen vu hungProof of Kraft Mc-Millan theorem - nguyen vu hung
Proof of Kraft Mc-Millan theorem - nguyen vu hung
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
Introduction to probability solutions manual
Introduction to probability   solutions manualIntroduction to probability   solutions manual
Introduction to probability solutions manual
 
Sequence and Series
Sequence and SeriesSequence and Series
Sequence and Series
 
Sequences And Series
Sequences And SeriesSequences And Series
Sequences And Series
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theorem
 
Number theory
Number theoryNumber theory
Number theory
 
P7
P7P7
P7
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
 
Scilab help book 2 of 2
Scilab help book 2 of 2Scilab help book 2 of 2
Scilab help book 2 of 2
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
Vectors2
Vectors2Vectors2
Vectors2
 
The 2 Goldbach's Conjectures with Proof
The 2 Goldbach's Conjectures with Proof The 2 Goldbach's Conjectures with Proof
The 2 Goldbach's Conjectures with Proof
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Divide and-conquer multiply two polynomials

  • 3. Presentation by_Hasanain ALshadoodee 3 Introduction  Multiplying Polynomials To multiply two polynomials together, multiply every term of one polynomial by every term of the other polynomial.
  • 4. Divide-and-Conquer Multiply two polynomials  Problem Given two polynomials represented by two arrays, write a function that multiplies given two polynomials. Input: A[] = {10, 5, 11} B[] = {3, 2, 1} Output: prod C[] = 10 X + 5 x1 + 11 x2 3 X + 2 x1 + 1 x2 = 30 + 10 * 2x1 + 10 * 1x1 + 5x1 * 3+ 5x1 * 2x1 + 5x1 * 1x2 + 11x2 * 3 + 11x2 * 2x1 + 11x2 * 1x2 polynomials Presentation by_Hasanain ALshadoodee 4
  • 5. Naïve Method One by one consider every term of first polynomial and multiply it with every term of second polynomial this will take O(n2) time complexity . Presentation by_Hasanain ALshadoodee 5
  • 6. Algoritham 1) Create a product array prod[] of size m+n-1. 2) Initialize all entries in prod[] as 0. 3) Traverse array A[] and do following for every element A[i] Traverse array B[] and do following for every element B[j] so prod[i+j] = prod[i+j] + A[i] * B[j] 4) Return prod[]. Presentation by_Hasanain ALshadoodee 6
  • 7. Analysis of Naïve Method  Time complexity of the above solution is O(mn).  If size of two polynomials same, then time complexity is O(n2). There are method to do multiplication faster that O(n2) time. This is method are based on Divide and conquer technique . Presentation by_Hasanain ALshadoodee 7
  • 8. Divide and Conquer Method Presentation by_Hasanain ALshadoodee 8 Let the two given polynomials be A and B. For simplicity, Let us assume that the given two polynomials are of same degree and have degree in powers of 2, i.e., n = 2i * polynomial 'A' can be written as A0 + A1* xn/2 * polynomial 'B' can be written as B0 + B1* xn/2
  • 9. Presentation by_Hasanain ALshadoodee Example polynomial A=2 + 3x + 6x2 - 2x3 + 5x4 polynomial B=1 - 6x + 7x2 + 2x3 + 8x4 Polynomial A=(2 + 3x) + (6 - 2x + 5x2 ) x2 A0 A1 polynomial B=(1 - 6x) + (7 + 2x + 8x2 ) x2 B0 B1 A * B = (A0 + A1*xn/2) * (B0 + B1*xn/2) = A0*B0 + A0*B1*xn/2 + A1*B0*xn/2 + A1*B1*xn = A0*B0 + (A0*B1 + A1*B0)xn/2 + A1*B1*xn
  • 10. Example  IN the example we can see divide and conquer method requires 4 multiplication and O(n) time to add all 4 results . T(n)=4T(n/2) + O(n) The solution of recurrence is O(n2) . But it can be reduced . T(n)=3T(n/2) + O(n) Using stressing matrix multiplication . Presentation by_Hasanain ALshadoodee 10
  • 11. Programming and Data Structures Presentation by_Hasanain ALshadoodee 11  Consider the following polynomials Each term of the polynomial 1 must be multiplied with each term of the polynomial Multiplying each term means multiplying their coefficients and adding their 1 2
  • 12. Consider the following polynomials Presentation by_Hasanain ALshadoodee 12 Resultant polynomial
  • 13. Consider the following polynomials Presentation by_Hasanain ALshadoodee 13 head1 head2 ptr2 ptr1 We need pointers (ptr1 and otr2) for traversal , so we also need a nested loop as each term of the first polynomial must be multiplied with every term of second polynomial.
  • 14. Consider the following polynomials Presentation by_Hasanain ALshadoodee 14 head1 head2 ptr2 ptr1 While (ptr1 != NULL)  While (ptr2 != NULL)   
  • 15. Consider the following polynomials Presentation by_Hasanain ALshadoodee 15 head1 head2 head3 Int res1 , res2 ; Struct node * head3=NULL; While (ptr1 != NULL)  Ptr2=head2; While (ptr2 != NULL)    ptr1=ptr1-> link;
  • 16. Presentation by_Hasanain ALshadoodee 16 Consider the following polynomials Resultant polynomial We will get this polynomial of term executing the cod be causes of insert function
  • 17. References  Section 5.6 of the text book “algorithm design” by Jon Kleinberg and Eva Tardos.  The original slides were prepared by Kevin Wayne. The slides are distributed by Pearson Addison-Wesley.  Wireless Algorithms, Systems, and Applications: 9th International Conference .  Crack GATE & ESE with Unacademy : Divide and Conquer: Multiply 2 Polynomials.  Important Links • Submit your work here: https://jovian.ai/learn/data-structures-and-algorithms-in-python/assignment/assignment-3- sorting-and-divide-conquer-practice • Ask questions and get help: https://jovian.ai/forum/c/data-structures-and-algorithms-in-python/assignment-3/89 • Lesson 3 video for review: https://jovian.ai/learn/data-structures-and-algorithms-in-python/lesson/lesson-3-sorting- algorithms-and-divide-and-conquer • Lesson 3 notebook for review: https://jovian.ai/aakashns/python-sorting-divide-and-conquer • Algebra I #5.11, Multiply two Polynomials https://www.youtube.com/watch?v=VAELGq-FViY • Application of Linked List (Multiplication of Two Polynomials) https://www.youtube.com/hashtag/linkedlist Presentation by_Hasanain ALshadoodee 17