Professional Documents
Culture Documents
(Deemed to be University)
On
SUBMITTED BY:
2200030518 Srivalli A
Asst.Proffessor
KLEF
CERTIFICATE
I express the sincere gratitude to our principal Dr. A. Jagadeesh for his
administration towards our academic growth.
1 Introduction <6>
5 Flowchart <12-15>
6 Implementation <16-29>
8 Conclusion <32-33>
INTRODUCTION
Linked lists are widely used data structures in computer science due to their dynamic
memory allocation and efficient insertion and deletion operations. One of the most
important applications of linked lists is in polynomial operations, such as addition,
subtraction, multiplication, and derivation. In this project, the goal is to implement these
polynomial operations using linked lists, where each polynomial is represented as a
linked list with each node containing information about the coefficient, exponent, and link
to the next term. This project requires a strong understanding of creating and using
linked lists, pointers, self-referential structures, and polynomial operations. By
implementing this project, students can gain valuable experience in working with linked
lists and applying them to real-world problems.
AIM
• To Implement the Linked List Applications for polynomial Equations.
Advantages:-
Dynamic memory allocation: Linked lists allow for dynamic memory allocation, which
means that the size of the polynomial can be increased or decreased as needed during
runtime. This provides flexibility and efficient memory usage.
Efficient insertion and deletion: Linked lists provide efficient insertion and deletion of nodes,
which is essential for polynomial operations. Since polynomials can have terms added or
removed, linked lists provide a suitable way to accomplish these operations.
Space efficiency: Linked lists are space-efficient compared to arrays. Since the size of the
polynomial can vary, using an array to represent a polynomial may result in wasted
memory. Linked lists, on the other hand, only use memory for the nodes they contain, which
means there is no wasted memory.
Ease of implementation: Linked lists are relatively easy to implement, especially compared
to other data structures such as trees or graphs. This makes it an ideal data structure to
represent polynomials in polynomial operations.
Overall, using linked lists in polynomial operations provides a flexible, efficient, and space-
saving solution that is easy to implement.
Disadvantages:-
Memory overhead: Linked lists have memory overhead due to the need for each node to
store the address of the next node. This can increase the memory usage of the program and
can be a concern for large polynomials.
Sequential access: Linked lists do not support random access, which can be a disadvantage
in some polynomial operations. For example, if we need to access the nth term of a
polynomial, we have to traverse the linked list from the beginning to reach that term.
Time complexity: Some operations on linked lists, such as traversing the list or searching for
a specific node, can have a time complexity of O(n), where n is the number of nodes in the
list. This can affect the performance of polynomial operations, especially for large
polynomials.
Implementation complexity: While linked lists are relatively easy to implement compared to
other data structures, they still require careful implementation to ensure that they work
correctly. This can be a challenge for inexperienced programmers.
Future enhancements:-
Optimization of time complexity: One of the challenges of using linked lists in polynomial
operations is the time complexity of certain operations. Future enhancements could focus on
optimizing the time complexity of these operations to improve the performance of polynomial
operations.
Support for parallel processing: With the increasing use of parallel processing, future
enhancements could focus on developing algorithms for polynomial operations that can be
parallelized to take advantage of multiple cores or processors.
Implementation of more advanced polynomial operations: While the four basic polynomial
operations (addition, subtraction, multiplication, and derivation) can be implemented using
linked lists, there are more advanced polynomial operations that could be developed. For
example, polynomial interpolation or polynomial division.
Integration with other data structures: While linked lists are a suitable data structure for
polynomial operations, there are other data structures that could be used in combination with
linked lists to improve performance. For example, using a hash table to store and retrieve
nodes in the linked list could improve the time complexity of certain operations.
SYSTEM REQUIREMENTS
➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system: Windows Xp or later.
➢ HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM :16GB
Polynomial Addition:
Define a function that takes two linked lists, each representing a polynomial, as
input.
Initialize a new linked list to represent the sum of the two polynomials.
Traverse the two input linked lists simultaneously, starting from the head of each
list.
For each node in the two input linked lists, add the coefficients of the two terms
with the same exponent and append a new node with the resulting coefficient and
exponent to the output linked list.
If one of the input linked lists has more terms than the other, append the
remaining terms to the output linked list.
Polynomial Subtraction:
Define a function that takes two linked lists, each representing a polynomial, as
input.
Initialize a new linked list to represent the difference of the two polynomials.
Traverse the two input linked lists simultaneously, starting from the head of each
list.
For each node in the two input linked lists, subtract the coefficients of the two
terms with the same exponent and append a new node with the resulting
coefficient and exponent to the output linked list.
If one of the input linked lists has more terms than the other, append the
remaining terms (with their coefficients negated) to the output linked list.
Polynomial Multiplication:
Define a function that takes two linked lists, each representing a polynomial, as
input.
Initialize a new linked list to represent the product of the two polynomials.
Traverse the first input linked list, starting from the head of the list.
For each node in the first input linked list, traverse the second input linked list,
starting from the head of the list.
For each node in the second input linked list, multiply the coefficients of the two
terms and add their exponents. Append a new node with the resulting coefficient
and exponent to the output linked list.
If the output linked list already contains a node with the same exponent as the
new node being appended, add the new coefficient to the coefficient of the
existing node.
Polynomial Derivation:
Traverse the input linked list, starting from the head of the list.
For each node in the input linked list, compute the derivative of the term by
multiplying the coefficient by the exponent and reducing the exponent by 1.
Append a new node with the resulting coefficient and exponent to the output
linked list.
If the resulting exponent is negative, do not append the new node to the output
linked list.
#include<stdlib.h>
struct node {
int coef,expo;
}*head=NULL,*head2=NULL,*mul1=NULL;
struct neekuenduk {
int coef;
int expo;
}*headmul=NULL;
void mul();
void add();
void sub();
void polynomial_1();
void polynomial_2();
void derivation();
void choice()
printf("3. ADD\n");
printf("4. SUBTRACT\n");
printf("5. MULTIPLY\n");
printf("6. DERIVATION\n");
printf("7. EXIT\n");
int n;
scanf("%d",&n);
switch(n)
case 1:
polynomial_1();
return choice();
break;
case 2:
polynomial_2();
return choice();
break;
case 3:
add();
return choice();
break;
case 4:
sub();
return choice();
break;
case 5:
mul();
return choice();
break;
case 6:
derivation();
return choice();
break;
case 7: exit(0);
void polynomial_1()
int f,i;
scanf("%d",&f);
for(i=0;i<f;i++)
scanf("%d",&new->coef);
scanf("%d",&new->expo);
new->next=NULL;
if (head==NULL)
head=new;
}
else
temp=head;
if (temp->expo>new->expo)
temp=temp->next;
temp->next=new;
else
new->next=head;
head=new;
void polynomial_2()
int f,i;
scanf("%d",&f);
for(i=0;i<f;i++)
{
scanf("%d",&new2->coef);
scanf("%d",&new2->expo);
new2->next=NULL;
if (head2==NULL)
head2=new2;
else
temp2=head2;
if (temp2->expo>new2->expo)
temp2=temp2->next;
temp2->next=new2;
else
new2->next=head2;
head2=new2;
void add()
temp=head;
temp2=head2;
while(temp->next!=NULL || temp2->next!=NULL)
if(temp->expo==temp2->expo)
printf("%d",temp->coef+temp2->coef);
printf("x^");
printf("%d+",temp->expo);
temp=temp->next;
temp2=temp2->next;
else
if (temp->coef>temp2->coef)
{
printf("%dx^%d+ ",temp->coef,temp->expo);
temp=temp->next;
else if(temp->coef<temp2->coef)
printf("%dx^%d+ ",temp2->coef,temp2->expo);
temp2=temp2->next;
printf("%dx^%d",temp->coef+temp2->coef,temp->expo);
printf("%dx^%d ",(temp->coef+temp2->coef),temp->expo);
else
if (temp->expo==0)
printf("%dx^%d ",temp->coef,temp->expo);
else if (temp2->expo==0)
printf("%dx^%d ",temp2->coef,temp2->expo);
}
}
void sub()
temp=head;
temp2=head2;
while(temp->next!=NULL || temp2->next!=NULL)
if(temp->expo==temp2->expo)
printf("%d",temp->coef-temp2->coef);
printf("x^");
printf("%d+",temp->expo);
temp=temp->next;
temp2=temp2->next;
else
if (temp->coef>temp2->coef)
printf("%dx^%d+ ",temp->coef,temp->expo);
temp=temp->next;
else if(temp->coef<temp2->coef)
{
printf("%dx^%d+ ",temp2->coef,temp2->expo);
temp2=temp2->next;
printf("%dx^%d",temp->coef-temp2->coef,temp->expo);
printf("%dx^%d ",(temp->coef-temp2->coef),temp->expo);
else
if (temp->expo==0)
printf("%dx^%d ",temp->coef,temp->expo);
else if (temp2->expo==0)
printf("%dx^%d ",temp2->coef,temp2->expo);
}
void mul()
while(temp1!=NULL)
temp2=head2;
while(temp2!=NULL)
new->coef=temp1->coef*temp2->coef;
new->expo=temp1->expo+temp2->expo;
new->next=NULL;
temp2=temp2->next;
if(mul1==NULL)
mul1=new;
else
while(temp0->next!=NULL)
temp0=temp0->next;
}
temp0->next=new;
temp1=temp1->next;
//hi
new1->coef=0;
new1->expo=4;
new1->next=NULL;
headmul=new1;
temp20=new1;
// hi
temp20->next=new2;
temp20=new2;
new2->coef=0;
new2->expo=3;
new2->next=NULL;
//hi
temp20->next=new3;
temp20=new3;
new3->coef=0;
new3->expo=2;
new3->next=NULL;
//hi
temp20->next=new4;
temp20=new4;
new4->coef=0;
new4->expo=1;
new4->next=NULL;
while(naestam!=NULL)
if(naestam->expo==4)
headmul->coef=headmul->coef+naestam->coef;
else if(naestam->expo==3)
temp3->coef=temp3->coef+naestam->coef;
else if(naestam->expo==2)
temp22->coef=temp22->coef+naestam->coef;
}
else if(naestam->expo==1)
temp11->coef=temp11->coef+naestam->coef;
naestam=naestam->next;
while(temp600->next!=NULL)
printf("%dX^%d+ ",temp600->coef,temp600->expo);
temp600=temp600->next;
printf("%dX^%d ",temp600->coef,temp600->expo);
free(mul1);
free(headmul);
void derivation()
while(temp->next!=NULL)
printf("%dx%d+",temp->expo*temp->coef,temp->expo-1);
temp=temp->next;
}
printf("%dx%d\n",temp->expo*temp->coef,temp->expo-1);
while(temp1->next!=NULL)
printf("%dx^%d+",temp1->expo*temp1->coef,temp1->expo-1);
temp1=temp1->next;
printf("%dx^%d\n",temp1->expo*temp1->coef,temp1->expo-1);
int main()
choice();
return 0;
}
RESULTS AND SCREENSHOTS
OUTPUTS
Screen Shots:
CONCLUSION
The user is presented with a menu that includes the options to store the values of the
first and second polynomials, add, subtract, multiply and derive polynomials, or exit the
program.
If the user chooses to store the values of the first polynomial, the program asks the user
to enter the number of values and then asks for the coefficient and exponent of each
term. The program then creates a linked list that represents the polynomial in
descending order of exponents.
If the user chooses to store the values of the second polynomial, the program does the
same thing as for the first polynomial.
If the user chooses to add or subtract polynomials, the program traverses both linked
lists and performs the operation. The result is printed out in descending order of
exponents.
If the user chooses to multiply polynomials, the program traverses both linked lists and
creates a new linked list that represents the resulting polynomial. The result is printed
out in descending order of exponents.
If the user chooses to derive a polynomial, the program traverses the linked list
representing the polynomial and creates a new linked list that represents the derivative
of the polynomial. The result is printed out in descending order of exponents.
Note that the program assumes that the polynomials are stored in descending order of
exponents. If the user enters the terms of a polynomial in ascending order of exponents,
the program will not work correctly. Also, the program does not perform any error
checking on user input, so it may crash if the user enters invalid input.
This project is beneficial for students who are interested in pursuing a career in
computer science, mathematics, or engineering. It provides them with the opportunity
to gain hands-on experience in implementing complex algorithms using linked lists and
pointers. By completing this project, students will develop problem-solving skills,
critical thinking, and programming skills.