SlideShare a Scribd company logo
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

PPTX
Polynomials
PPTX
Polynomials
PPTX
Polynomial equations
PPTX
Polynomials (Algebra) - Class 10
PPT
Polynomial 
PPTX
Polynomials
PPT
Polynomials Add And Subtract Ch 9.1
PPTX
Polynomials
Polynomials
Polynomials
Polynomial equations
Polynomials (Algebra) - Class 10
Polynomial 
Polynomials
Polynomials Add And Subtract Ch 9.1
Polynomials

What's hot (20)

PPTX
polynomials class 9th maths presentation
PPT
7.3 quadratic techniques
PPTX
Polynomials
PPTX
Diapositivas unidad 1
PPT
POLYNOMIALS
PDF
Introduction to polynomials
PPT
Polynomials
PPTX
Polynomials
PPTX
Edexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
PPTX
Polynomial function
PPTX
NCERT Class 9 Maths Polynomials
PPTX
Polynomials
PPTX
Long division, synthetic division, remainder theorem and factor theorem
PPT
Ch4 Polynomials
PDF
9-5 Notes
PPT
Algebra and functions review
PPTX
Linear equations in Two variables
PPTX
7 3 by linear combinations - day 1
PPT
Dividing Polynomials Slide Share
PPTX
Ankit maths ppt
polynomials class 9th maths presentation
7.3 quadratic techniques
Polynomials
Diapositivas unidad 1
POLYNOMIALS
Introduction to polynomials
Polynomials
Polynomials
Edexcel Maths – Core 2 – Algebraic Division and Remainder Theorem
Polynomial function
NCERT Class 9 Maths Polynomials
Polynomials
Long division, synthetic division, remainder theorem and factor theorem
Ch4 Polynomials
9-5 Notes
Algebra and functions review
Linear equations in Two variables
7 3 by linear combinations - day 1
Dividing Polynomials Slide Share
Ankit maths ppt
Ad

Similar to Polynomial Expression (20)

PDF
Algorithms summary (English version)
PPTX
Recurrent Problem in Discrete Mathmatics.pptx
PPTX
unit-3-permutation_combination.pptx
PPTX
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...
PPTX
Sorting and hashing concepts
PPTX
Sorting and hashing concepts
PPT
Data structure lecture 4
PPTX
data structures and applications power p
PPT
Cs1311lecture23wdl
PDF
Trees second part in data structures with examples
PPTX
CIRCULAR LINKED LIST _
PDF
In three of the exercises below there is given a code of a method na.pdf
PPT
Data Structure (MC501)
PPTX
Lecture 1-number synthesis
PPTX
Lec 03 - Sorting.pptx
PPTX
1.2 tables
PPTX
Permutation and combination
PPTX
Searching and sorting Techniques in Data structures
PPTX
Unit1_UniqueRectangles (4).pptx.It is of topics dsa only again.
PDF
List , tuples, dictionaries and regular expressions in python
Algorithms summary (English version)
Recurrent Problem in Discrete Mathmatics.pptx
unit-3-permutation_combination.pptx
Counting, pigeonhole, permuntation, Permutations and Combination ,Binomial T...
Sorting and hashing concepts
Sorting and hashing concepts
Data structure lecture 4
data structures and applications power p
Cs1311lecture23wdl
Trees second part in data structures with examples
CIRCULAR LINKED LIST _
In three of the exercises below there is given a code of a method na.pdf
Data Structure (MC501)
Lecture 1-number synthesis
Lec 03 - Sorting.pptx
1.2 tables
Permutation and combination
Searching and sorting Techniques in Data structures
Unit1_UniqueRectangles (4).pptx.It is of topics dsa only again.
List , tuples, dictionaries and regular expressions in python
Ad

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Sustainable Sites - Green Building Construction
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
composite construction of structures.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Geodesy 1.pptx...............................................
PPTX
Construction Project Organization Group 2.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Welding lecture in detail for understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
Project quality management in manufacturing
573137875-Attendance-Management-System-original
Lecture Notes Electrical Wiring System Components
Operating System & Kernel Study Guide-1 - converted.pdf
Sustainable Sites - Green Building Construction
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
composite construction of structures.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CH1 Production IntroductoryConcepts.pptx
Mechanical Engineering MATERIALS Selection
Geodesy 1.pptx...............................................
Construction Project Organization Group 2.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Welding lecture in detail for understanding
bas. eng. economics group 4 presentation 1.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Project quality management in manufacturing

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