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 = 5x^2 + 4x^1 + 2x^0 2nd number = 5x^1 + 5x^0 Output: 5x^2 + 9x^1 + 7x^0 Input: 1st number = 5x^3 + 4x^2 + 2x^0 2nd number = 5x^1 + 5x^0 Output: 5x^3 + 4x^2 + 5x^1 + 7x^0
1st Number: 5x^2 + 4x^1 + 2x^0 2nd Number: 5x^1 + 5x^0 Added polynomial: 5x^2 + 9x^1 + 7x^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 email@example.com. 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.
- Multiplication of two polynomials using Linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Convert singly linked list into circular linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Merge a linked list into another linked list at alternate positions
- Check if a linked list is Circular Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Length of longest palindrome list in a linked list using O(1) extra space
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Rotate the sub-list of a linked list from position M to N to the right by K places
- Program to add two polynomials
- Multiply two polynomials
- First non-repeating in a linked list
- Generic Linked List in C
- Linked List | Set 1 (Introduction)