Module-2-DSA-T5-Application of List
Module-2-DSA-T5-Application of List
BCSE202L -
COURSE INSTRUCTOR: DATA STRUCTURES AND
DR. OM KUMAR C.U. ALGORITHMS
ASSISTANT PROFESSOR,
SCOPE,VIT.
A( x ) am 1 x em 1 a0 x e0
Add two
polynomials
Analysis of padd
A( x )( am 1 x em 1 a0 x e0 ) B ( x )( bn 1 x f n 1 b0 x f0 )
1. coefficient additions
0 additions min(m, n)
where m (n) denotes the number of terms in A (B).
2. exponent comparisons
extreme case:
em-1 > fm-1 > em-2 > fm-2 > … > e1 > f1 > e0 > f0
m+n-1 comparisons
3. creation of new nodes
extreme case: maximum number of terms in d is m+n m + n new
nodes
summary: O(m+n)
DR. OM KUMAR C.U. 20/01/2025 9
POLYNOMIALS (8/9)
print_poly(e);
POLYNOMIALS (9/9)
Erase Polynomials
erase frees the nodes in temp
void erase (poly_pointer *ptr){
/* erase the polynomial pointed to by ptr */
poly_pointer temp;
while ( *ptr){
temp = *ptr;
*ptr = (*ptr) -> link;
DR. OM KUMAR C.U.
free(temp); 20/01/2025 11
}}
THANK YOU