Given two polynomial numbers represented by a linked list. Write a function that add these lists means add the coefficients who have same variable powers.
Input: 1st number = 5x2 + 4x1 + 2x0 2nd number = -5x1 - 5x0 Output: 5x2-1x1-3x0 Input: 1st number = 5x3 + 4x2 + 2x0 2nd number = 5x^1 - 5x^0 Output: 5x3 + 4x2 + 5x1 - 3x0
1st Number: 5x^2+4x^1+2x^0 2nd Number: -5x^1-5x^0 Added polynomial: 5x^2-1x^1-3x^0
Time Complexity: O(m + n) where m and n are number of nodes in first and second lists respectively.
Related Article: Add two polynomial numbers using Arrays
This article is contributed by Akash Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Adding two polynomials using Linked List using map
- Adding two polynomials using Circular Linked List
- Multiplication of two polynomials using Linked list
- Multiply two polynomials
- Program to add two polynomials
- Create new linked list from two given linked list with greater element at each node
- Remainder Theorem - Polynomials | Class 9 Maths
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Check if a linked list is Circular Linked List
- Convert Singly Linked List to XOR Linked List
- Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Length of longest palindrome list in a linked list using O(1) extra space
- Construct a Doubly linked linked list from 2D Matrix
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
Improved By : aniket173000