{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lect31 - DS CS 11002 Computer Sc Engg IIT Kharagpur \$ 1...

This preview shows pages 1–14. Sign up to view the full content.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 & \$ % Data Type III Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 & \$ % A Polynomial Over R A polynomial over the real numbers is written as p ( x ) = a 0 + a 1 x + a 2 x 2 + · · · + a n - 1 x n - 1 , where all a i ’s are real numbers and x is the formal variable . Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 3 & \$ % A Polynomial Over R A polynomial may be viewed as a finite sequence of real numbers or an infinite sequence with finite number of non-zero elements. ( a 0 , a 1 , a 2 , · · · , a n - 1 ) or ( a 0 , a 1 , a 2 , · · · , a n - 1 , 0 , 0 , · · · ). The degree of a polynomial p ( x ) is n , if the coefficient of x n is non-zero and the coefficients of all higher powers of x are zero. Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 4 & \$ % Data in a Polynomial Essential data in a polynomial is a finite sequence of ( a i , n i ) pairs, where each pair corresponds to the term a i x n i . It may also be necessary to remember the total number of terms or the degree of the polynomial. Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 5 & \$ % A Term The first component of the data in a term is a real number and may be approximated by a floating-point number in C language. The second component is a positive integer and may be approximated by an int or unsigned int . Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 6 & \$ % Representation I We may store the coefficients ( a i ) in a 1-D array of type float or double where the index of the array corresponds to n i . We may explicitly store the degree of the polynomial or put a terminator e.g. (have representation in IEEE format), after the last non-zero coefficient. Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 7 & \$ % 3 . 0 + 1 . 5 x 2 + 5 . 5 x 6 0 1 2 3 4 5 6 7 8 9 3.0 1.5 5.5 0.0 0.0 0.0 0.0 0.0 0.0 α Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 8 & \$ % 3 . 0 + 1 . 5 x 2 + 5 . 5 x 6 0 1 2 3 4 5 6 7 8 9 3.0 1.5 5.5 0.0 0.0 0.0 0.0 0.0 0.0 6 0.0 Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 9 & \$ % Note The main problem of this representation is that it stores the zero coefficients. But the advantage is that no extra space is required to store the power of x . #define MAXDEG 100 typedef struct { float coeff[MAXDEG]; int maxDeg; } polynomial; Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 10 & \$ % Representation II We may store the ( a i , n i ) pairs explicitly as a structure of type term and whole polynomial as an array of terms. Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 11 & \$ % 3 . 0 + 1 . 5 x 2 + 5 . 5 x 6 0 1 2 3 4 5 6 7 8 9 3.0 0.0 0 1.5 2 5.5 6 3 Lect 31 Goutam Biswas

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 12 & \$ % Type Definition #define MAXTRM 100 typedef struct { int power; float coeff; } term; typedef struct { term coeff[MAXTRM]; int termCount; } polynomial; Lect 31 Goutam Biswas
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 13 & \$ % Representation III The polynomial may be stored as an ordered linked-list (singly-linked) or (doubly-linked).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 55

lect31 - DS CS 11002 Computer Sc Engg IIT Kharagpur \$ 1...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online