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)

PPTX
CIRCULAR LINKED LIST _
PDF
Circular linked list
PPT
cp264_lecture13_14_linkedlist.ppt
PPT
Lecture4
PPTX
Linked list data structures and algorithms
PPT
computer notes - Data Structures - 4
PPT
358 33 powerpoint-slides_8-linked-lists_chapter-8
PDF
The following code is based on the Josephus problem, the code does c.pdf
PPT
Linked lists
PPTX
Data structures
PPT
Circular_Linked_List.ppt
PPTX
Deleting a node from the list(SINGLE LINKED LIST)
PPTX
Doubly & Circular Linked Lists
PDF
template ltclass Tgt struct nodeType T data n.pdf
PPTX
1.3 Linked List.pptx
DOC
Linked List
PPT
Linkedlists
PPTX
Circular linked list
PPTX
Data structure and algorithm list structures
PPT
Circular linked list
CIRCULAR LINKED LIST _
Circular linked list
cp264_lecture13_14_linkedlist.ppt
Lecture4
Linked list data structures and algorithms
computer notes - Data Structures - 4
358 33 powerpoint-slides_8-linked-lists_chapter-8
The following code is based on the Josephus problem, the code does c.pdf
Linked lists
Data structures
Circular_Linked_List.ppt
Deleting a node from the list(SINGLE LINKED LIST)
Doubly & Circular Linked Lists
template ltclass Tgt struct nodeType T data n.pdf
1.3 Linked List.pptx
Linked List
Linkedlists
Circular linked list
Data structure and algorithm list structures
Circular linked list
Ad

Recently uploaded (20)

PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
PPTX
Software Engineering and software moduleing
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PPTX
ai_satellite_crop_management_20250815030350.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
DOC
T Pandian CV Madurai pandi kokkaf illaya
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PPTX
PRASUNET_20240614003_231416_0000[1].pptx
PPTX
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PPTX
Module 8- Technological and Communication Skills.pptx
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
First part_B-Image Processing - 1 of 2).pdf
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
Software Engineering and software moduleing
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
ai_satellite_crop_management_20250815030350.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
T Pandian CV Madurai pandi kokkaf illaya
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PRASUNET_20240614003_231416_0000[1].pptx
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
Module 8- Technological and Communication Skills.pptx
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
Management Information system : MIS-e-Business Systems.pptx
First part_B-Image Processing - 1 of 2).pdf
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...

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