SlideShare a Scribd company logo
1 of 13
Data Stucture
Unit II
POLYNOMIAL EXPRESSION USING LINKED LIST
Polynomial Expression using Linked
List
• linked list is a data structure that stores each
element as an object in a node of the list.
• Polynomial is a mathematical expression that
consists of variables and coefficients.
• For example: 5x^2 - 4x + 7
• 3x+ 3
• result = 5x^2-x+10
Polynomial Expression using Linked
List
• In the Polynomial linked list, the coefficients and
exponents of the polynomial are defined as the
data node of the list.
• Implementation of polynomial Expression,
struct node
{ int power;
float coef;
struct node *next;
};
Example
Adding two polynomials using Linked List
Input:
• 1st number = 5x^2 + 4x^1 + 2x^0
• 2nd number = 5x^1 + 5x^0
Output: 5x^2 + 9x^1 + 7x^0
Adding two polynomials using Linked List
Adding two polynomials using Linked List
Algorithm:
• Create Linked polynomials
• Read the co-efficient and exponent values
• Set the pointers list1 and list2 to both the polynomials
to traverse them.
• Start from the first node and compare the exponent of
polynomials.
• If(list1->exp == list2-> exp)
list1->coef= list1->coef + list2->coef
list3->exp= list1->exp
(move your pointer to next node)
Adding two polynomials using Linked List
Algorithm:
• If(list1->exp == list2-> exp)
list1->coef= list1->coef + list2->coef
list3->exp= list1->exp
(move both the pointer to next node)
• If(list1->exp > list2-> exp)
list3->coef= list1->coef
list3->exp= list1->exp
(move list1 pointer to next node)
• If(list1->exp < list2-> exp)
list3->coef= list2->coef
list3->exp= list2->exp
(move list2 pointer to next node)
Josephus Circle using circular linked list
• There are n people standing in a circle waiting to be executed.
• The counting out begins at some point in the circle and proceeds
around the circle in a fixed direction.
• In each step, a certain number of people are skipped and the next
person is executed.
• The elimination proceeds around the circle (which is becoming
smaller and smaller as the executed people are removed), until only
the last person remains, who is given freedom.
• Given the total number of persons n and a number m which
indicates that m-1 persons are skipped and m-th person is killed in
circle.
• The task is to choose the place in the initial circle so that you are
the last one remaining and so survive.
.
Josephus Circle using circular linked list
Algorithm:
1) Create a circular linked list of size n.
2) Traverse through linked list and one by
one delete every m-th node until there is one
node left.
3) Return value of the only left node.
Josephus Circle using circular linked list
Description:
• The Josephus problem involves n people standing in a
circle. Each person kills the next person until there is
only one person remaining. We will use a circular
linked list to solve the Josephus problem.
For example: n = 6,
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 1
• Node 1 kills node 2. Node 3 kills node 4. Node 5 kills
node 6.
1 -> 3 -> 5 -> 1
• Node 1 kills node 3. Node 5 kills node 1.
5 ->
• Therefore 5 is the last person remaining.
Josephus Circle using circular linked list
Example 1: n = 10, Rotate the list to the left by
one position and then delete the first element.
Find who is the lone survivor.
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7-> 8 -> 9 -> 10
Josephus Circle using circular linked list
Example 1: n = 10
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7-> 8 -> 9 -> 10

More Related Content

What's hot

polynomials class 9th maths presentation
polynomials class 9th maths presentationpolynomials class 9th maths presentation
polynomials class 9th maths presentationAnushkaDubey19
 
7.3 quadratic techniques
7.3 quadratic techniques7.3 quadratic techniques
7.3 quadratic techniquesJessica Garcia
 
Introduction to polynomials
Introduction to polynomialsIntroduction to polynomials
Introduction to polynomialsnarayana dash
 
Edexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
Edexcel Maths – Core 2 – Algebraic Division and Remainder TheoremEdexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
Edexcel Maths – Core 2 – Algebraic Division and Remainder TheoremUmayr Dawood
 
Polynomial function
Polynomial functionPolynomial function
Polynomial functionmaricel mas
 
NCERT Class 9 Maths Polynomials
NCERT Class 9 Maths  PolynomialsNCERT Class 9 Maths  Polynomials
NCERT Class 9 Maths PolynomialsPankajGahlot2
 
Long division, synthetic division, remainder theorem and factor theorem
Long division, synthetic division, remainder theorem and factor theoremLong division, synthetic division, remainder theorem and factor theorem
Long division, synthetic division, remainder theorem and factor theoremJohn Rome Aranas
 
Ch4 Polynomials
Ch4 PolynomialsCh4 Polynomials
Ch4 Polynomialsapplepi
 
7 3 by linear combinations - day 1
7 3 by linear combinations - day 17 3 by linear combinations - day 1
7 3 by linear combinations - day 1bweldon
 
Dividing Polynomials Slide Share
Dividing Polynomials Slide ShareDividing Polynomials Slide Share
Dividing Polynomials Slide ShareKristen T
 

What's hot (20)

polynomials class 9th maths presentation
polynomials class 9th maths presentationpolynomials class 9th maths presentation
polynomials class 9th maths presentation
 
7.3 quadratic techniques
7.3 quadratic techniques7.3 quadratic techniques
7.3 quadratic techniques
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Diapositivas unidad 1
Diapositivas unidad 1Diapositivas unidad 1
Diapositivas unidad 1
 
POLYNOMIALS
POLYNOMIALSPOLYNOMIALS
POLYNOMIALS
 
Introduction to polynomials
Introduction to polynomialsIntroduction to polynomials
Introduction to polynomials
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Edexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
Edexcel Maths – Core 2 – Algebraic Division and Remainder TheoremEdexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
Edexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
 
Polynomial function
Polynomial functionPolynomial function
Polynomial function
 
NCERT Class 9 Maths Polynomials
NCERT Class 9 Maths  PolynomialsNCERT Class 9 Maths  Polynomials
NCERT Class 9 Maths Polynomials
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Long division, synthetic division, remainder theorem and factor theorem
Long division, synthetic division, remainder theorem and factor theoremLong division, synthetic division, remainder theorem and factor theorem
Long division, synthetic division, remainder theorem and factor theorem
 
Ch4 Polynomials
Ch4 PolynomialsCh4 Polynomials
Ch4 Polynomials
 
9-5 Notes
9-5 Notes9-5 Notes
9-5 Notes
 
Algebra and functions review
Algebra and functions reviewAlgebra and functions review
Algebra and functions review
 
Linear equations in Two variables
Linear equations in Two variablesLinear equations in Two variables
Linear equations in Two variables
 
7 3 by linear combinations - day 1
7 3 by linear combinations - day 17 3 by linear combinations - day 1
7 3 by linear combinations - day 1
 
Dividing Polynomials Slide Share
Dividing Polynomials Slide ShareDividing Polynomials Slide Share
Dividing Polynomials Slide Share
 
Ankit maths ppt
Ankit maths pptAnkit maths ppt
Ankit maths ppt
 

Similar to Polynomial Expression

Algorithms summary (English version)
Algorithms summary (English version)Algorithms summary (English version)
Algorithms summary (English version)Young-Min kang
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxgbikorno
 
unit-3-permutation_combination.pptx
unit-3-permutation_combination.pptxunit-3-permutation_combination.pptx
unit-3-permutation_combination.pptxPradip738766
 
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...
Counting,  pigeonhole, permuntation, Permutations and Combination ,Binomial T...Counting,  pigeonhole, permuntation, Permutations and Combination ,Binomial T...
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...sheiblu
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing conceptsLJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing conceptsLJ Projects
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4Kumar
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power pMeghaKulkarni27
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdffeelinggift
 
Lecture 1-number synthesis
Lecture 1-number synthesisLecture 1-number synthesis
Lecture 1-number synthesismuhammadajmal119
 
1.2 tables
1.2 tables1.2 tables
1.2 tableshisema01
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonchanna basava
 
Array 2
Array 2Array 2
Array 2Abbott
 
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...rishi820219
 

Similar to Polynomial Expression (20)

Algorithms summary (English version)
Algorithms summary (English version)Algorithms summary (English version)
Algorithms summary (English version)
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptx
 
unit-3-permutation_combination.pptx
unit-3-permutation_combination.pptxunit-3-permutation_combination.pptx
unit-3-permutation_combination.pptx
 
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...
Counting,  pigeonhole, permuntation, Permutations and Combination ,Binomial T...Counting,  pigeonhole, permuntation, Permutations and Combination ,Binomial T...
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 
Cs1311lecture23wdl
Cs1311lecture23wdlCs1311lecture23wdl
Cs1311lecture23wdl
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdf
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
Lecture 1-number synthesis
Lecture 1-number synthesisLecture 1-number synthesis
Lecture 1-number synthesis
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
 
1.2 tables
1.2 tables1.2 tables
1.2 tables
 
Permutation and combination
Permutation and combinationPermutation and combination
Permutation and combination
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Array 2
Array 2Array 2
Array 2
 
Sorting
SortingSorting
Sorting
 
linked list
linked listlinked list
linked list
 
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...
Class 11 Applied mathematics Formula sheet_c88b01d2-a305-4e82-8384-9a47d968e1...
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 

Polynomial Expression

  • 1. Data Stucture Unit II POLYNOMIAL EXPRESSION USING LINKED LIST
  • 2. Polynomial Expression using Linked List • linked list is a data structure that stores each element as an object in a node of the list. • Polynomial is a mathematical expression that consists of variables and coefficients. • For example: 5x^2 - 4x + 7 • 3x+ 3 • result = 5x^2-x+10
  • 3. Polynomial Expression using Linked List • In the Polynomial linked list, the coefficients and exponents of the polynomial are defined as the data node of the list. • Implementation of polynomial Expression, struct node { int power; float coef; struct node *next; };
  • 5. Adding two polynomials using Linked List Input: • 1st number = 5x^2 + 4x^1 + 2x^0 • 2nd number = 5x^1 + 5x^0 Output: 5x^2 + 9x^1 + 7x^0
  • 6. Adding two polynomials using Linked List
  • 7. Adding two polynomials using Linked List Algorithm: • Create Linked polynomials • Read the co-efficient and exponent values • Set the pointers list1 and list2 to both the polynomials to traverse them. • Start from the first node and compare the exponent of polynomials. • If(list1->exp == list2-> exp) list1->coef= list1->coef + list2->coef list3->exp= list1->exp (move your pointer to next node)
  • 8. Adding two polynomials using Linked List Algorithm: • If(list1->exp == list2-> exp) list1->coef= list1->coef + list2->coef list3->exp= list1->exp (move both the pointer to next node) • If(list1->exp > list2-> exp) list3->coef= list1->coef list3->exp= list1->exp (move list1 pointer to next node) • If(list1->exp < list2-> exp) list3->coef= list2->coef list3->exp= list2->exp (move list2 pointer to next node)
  • 9. Josephus Circle using circular linked list • There are n people standing in a circle waiting to be executed. • The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. • In each step, a certain number of people are skipped and the next person is executed. • The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. • Given the total number of persons n and a number m which indicates that m-1 persons are skipped and m-th person is killed in circle. • The task is to choose the place in the initial circle so that you are the last one remaining and so survive. .
  • 10. Josephus Circle using circular linked list Algorithm: 1) Create a circular linked list of size n. 2) Traverse through linked list and one by one delete every m-th node until there is one node left. 3) Return value of the only left node.
  • 11. Josephus Circle using circular linked list Description: • The Josephus problem involves n people standing in a circle. Each person kills the next person until there is only one person remaining. We will use a circular linked list to solve the Josephus problem. For example: n = 6, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 1 • Node 1 kills node 2. Node 3 kills node 4. Node 5 kills node 6. 1 -> 3 -> 5 -> 1 • Node 1 kills node 3. Node 5 kills node 1. 5 -> • Therefore 5 is the last person remaining.
  • 12. Josephus Circle using circular linked list Example 1: n = 10, Rotate the list to the left by one position and then delete the first element. Find who is the lone survivor. 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7-> 8 -> 9 -> 10
  • 13. Josephus Circle using circular linked list Example 1: n = 10 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7-> 8 -> 9 -> 10