0% found this document useful (0 votes)
213 views4 pages

By Definition of A Data Types

A polynomial can be represented using arrays or linked lists. Array representation stores coefficients in array indices corresponding to exponents from 0 to the highest exponent. Linked list representation defines a structure containing a coefficient and exponent for each term, linked together. Common polynomial operations like addition and multiplication are then implemented by traversing the data structures and combining like terms.

Uploaded by

saravananaec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views4 pages

By Definition of A Data Types

A polynomial can be represented using arrays or linked lists. Array representation stores coefficients in array indices corresponding to exponents from 0 to the highest exponent. Linked list representation defines a structure containing a coefficient and exponent for each term, linked together. Common polynomial operations like addition and multiplication are then implemented by traversing the data structures and combining like terms.

Uploaded by

saravananaec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Representation of a Polynomial: A polynomial is an expression that contains more than two terms.

A term is made up of coefficient and exponent. An example of polynomial is

P(x) = 4x3+6x2+7x+9

A polynomial thus may be represented using arrays or linked lists. Array representation assumes
that the exponents of the given expression are arranged from 0 to the highest value (degree), which
is represented by the subscript of the array beginning with 0. The coefficients of the respective
exponent are placed at an appropriate index in the array. The array representation for the above
polynomial expression is given below:

A polynomial may also be represented using a linked list. A structure may be defined such that it
contains two parts- one is the coefficient and second is the corresponding exponent. The structure
definition may be given as shown below:

Struct polynomial
{
int coefficient;
int exponent;
struct polynomial *next;
};

Thus the above polynomial may be represented using linked list as shown below:

Addition of two Polynomials:

For adding two polynomials using arrays is straightforward method, since both the arrays may be
added up element wise beginning from 0 to n-1, resulting in addition of two polynomials. Addition of
two polynomials using linked list requires comparing the exponents, and wherever the exponents
are found to be same, the coefficients are added up. For terms with different exponents, the
complete term is simply added to the result thereby making it a part of addition result. The
complete program to add two polynomials is given in subsequent section.

Multiplication of two Polynomials:

Multiplication of two polynomials however requires manipulation of each node such that the
exponents are added up and the coefficients are multiplied. After each term of first polynomial is
operated upon with each term of the second polynomial, then the result has to be added up by
comparing the exponents and adding the coefficients for similar exponents and including terms as
such with dissimilar exponents in the result. The ‘C’ program for polynomial manipulation is given
below:

By definition of a data types:


 A set of values and a set of allowable operations on those values.
 We can now operate on this polynomial the way we like…
What kinds of operations?
Here are the most common operations on a polynomial:
 Add & Subtract
 Multiply
 Differentiate
 Integrate……etc…
Why implement this?

Calculating polynomial operations by hand can be very difficult.

Example :Take differentiation as an example:

d(23x9 + 18x7 + 41x6 + 163x4 + 5x + 3)/dx

= (23*9)x(9-1) + (18*7)x(7-1) + (41*6)x(6-1) + …

There are different ways of implementing the polynomial ADT:

• Array (not recommended)

• Linked List (preferred and recommended)

Advantages of using an Array:

• Only good for non-sparse polynomials.

• Ease of storage and retrieval.


Disadvantages of using an Array:

• have to allocate array size ahead of time.

• huge array size required for sparse polynomials.

• Waste of space and runtime

LINKED LIST IMPLEMENTATION

Advantages of using a Linked list:


• save space (don’t have to worry about sparse polynomials) and easy to maintain

• don’t need to allocate list size and can declare nodes (terms) only as needed

Disadvantages of using a Linked list :

• can’t go backwards through the list

• can’t jump to the beginning of the list from the end.

You might also like