---
title: "Polynomial representation and addition algorithm"
subject: "Data Structure and Algorithm"
chapter: 4
key: "semester_4/data_structure_and_algorithm:polynomial-representation-addition-algorithm"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/polynomial-representation-addition-algorithm
site: BCT Engineering
---

# Polynomial representation and addition algorithm

Data Structure and Algorithm · Chapter 4: Linked lists

- Asked in: 2069 Poush, 2+3 marks
- Video: [Application of Linked List (Addition of Two Polynomials)](https://www.youtube.com/watch?v=cFHZ-a87Vp4) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/polynomial-representation-addition-algorithm
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-4

## Question

How do you represent polynomial equation using linked list? Write an algorithm to add two polynomial equations.

## Short answer

Polynomial terms are stored as nodes (coef, exp, next) in descending exponent order. Addition: traverse both lists, compare exponents; if p.exp > q.exp, append p's term; if <, append q's term; if equal, add coefficients (if non-zero append). Append remaining terms from the non-empty list. Time O(m+n).

## Answer

#### Representation
Each non-zero term of the polynomial is one node holding the coefficient, the exponent and a pointer to the next term. The terms are stored in decreasing order of exponent.

```c
struct term { int coef; int exp; struct term *next; };
```
Example: 7x⁴ − 3x² + 5
```text
poly -> [7|4]->[-3|2]->[5|0]->NULL
```

#### Algorithm POLYADD(p, q)  -> result list r
1. Set r = NULL (empty). Let p, q point to the first terms.
2. While p ≠ NULL and q ≠ NULL:
   - If p->exp > q->exp: append term (p->coef, p->exp) to r; p = p->next.
   - Else if p->exp < q->exp: append (q->coef, q->exp) to r; q = q->next.
   - Else: s = p->coef + q->coef; if s ≠ 0 append (s, p->exp) to r; p = p->next; q = q->next.
3. While p ≠ NULL: append p's term to r; p = p->next.
4. While q ≠ NULL: append q's term to r; q = q->next.
5. Return r.

Example: (3x³ + 2x + 1) + (4x² − 2x + 6)

| p term | q term | Action | r |
|---|---|---|---|
| 3x³ | 4x² | p bigger, copy 3x³ | 3x³ |
| 2x | 4x² | q bigger, copy 4x² | 3x³ + 4x² |
| 2x | −2x | equal, sum 0, drop | 3x³ + 4x² |
| 1 | 6 | equal, 1+6 = 7 | 3x³ + 4x² + 7 |

Time is O(m + n) for m and n terms.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is a polynomial stored using a linked list?
   A. One node per non-zero term holding coef, exp and next, in decreasing exponent order
   B. One node per power including zero coefficients
   C. Coefficients in an array, one node
   D. One node per variable x
   Answer: A. Only non-zero terms are stored, ordered to allow merge-like addition. (Key point: Representation)

2. What happens when terms with equal exponent have coefficients that sum to 0?
   A. A node with coefficient 0 is appended
   B. The term is dropped from the result
   C. The algorithm stops
   D. The exponent is reduced
   Answer: B. A zero coefficient term does not exist in the result polynomial. (Key point: Zero sum)

3. After one list is exhausted, what is done?
   A. The result is returned immediately
   B. They are discarded
   C. Remaining terms of the other list are copied to the result
   D. They are added to zero and dropped
   Answer: C. Those terms have no partner to combine with. (Key point: Leftover terms)

4. (3x^3 + 2x + 1) + (4x^2 - 2x + 6) gives?
   A. 3x^3 + 4x^2 + 4x + 7
   B. 7x^3 + 7
   C. 3x^3 + 4x^2 - 5
   D. 3x^3 + 4x^2 + 7
   Answer: D. The 2x and -2x cancel; 1 + 6 = 7. (Key point: Example result)

## Related in Data Structure and Algorithm

- [Polynomial addition using linked list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Apolynomial-addition-linked-list) — Data Structure and Algorithm, chapter 4, asked 3×
- [Algorithm to create a single linked list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Acreate-single-linked-list) — Data Structure and Algorithm, chapter 4

## Related in other subjects

- [Add objects of two different classes](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afriend-add-two-class-objects) — Object Oriented Programming, chapter 4, asked 2×
- [Algorithm for unsteady pipe flow FD equations](https://www.bctengineer.com/question.md?key=semester_8%2Fcomputational_techniques_in_civil_engineering%3Aalgorithm-pipe-fd-hp-equations) — Computational Techniques in Civil Engineering, chapter 6
- [Time class: add two objects](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Atime-class-add-objects) — Object Oriented Programming, chapter 1
- [8085 ALP: add two tables, sum and carry](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-add-two-tables) — Microprocessor, chapter 2
