You are on page 1of 33

Koneru Lakshmaiah Education Foundation

(Deemed to be University)

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report

On

Implementation Of Linked List Applications

SUBMITTED BY:

I.D NUMBER NAME

2200030518 Srivalli A

UNDER THE GUIDANCE OF

Dr. Deepak Kumar Panda

Asst.Proffessor

KLEF

Green fields, Vaddeswaram – 522 302


Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES-1

CERTIFICATE

This is to certify that the project based laboratory report entitled


“Implementation Of Linked List Applications” submitted by Ms. A.Srivalli bearing
Regd. No. 2200030518 to the Department of Basic Engineering Sciences-1, KL
University in partial fulfillment of the requirements for the completion of a
project based Laboratory in “COMPUTATIONAL THINKING FOR STRUCTURED
DESIGN”course in I B Tech I Semester, is a bonafide record of the work carried out
by him/her under my supervision during the academic year 2022 – 2023.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

Dr.Deepak kumar Panda Dr.D.Haritha


ACKNOWLEDGEMENTS

It is great pleasure for me to express my gratitude to our honorable


President Sri. Koneru Satyanarayana, for giving the opportunity and platform
with facilities in accomplishing the project based laboratory report.

I express the sincere gratitude to our principal Dr. A. Jagadeesh for his
administration towards our academic growth.

I express sincere gratitude to HOD-BES-1 Dr. D. Haritha for her leadership


and constant motivation provided in successful completion of our academic
semester. I record it as my privilege to deeply thank for providing us the efficient
faculty and facilities to make our ideas into reality.

I express my sincere thanks to our project supervisor Ms.Syed


Karimunnisa for her novel association of ideas, encouragement, appreciation and
intellectual zeal which motivated us to venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who


devoted themselves directly or indirectly to make this project report success.

Name: A.Srivalli Regd . No: 2200030518


ABSTRACT

This project aims to implement various polynomial operations such as addition,


subtraction, multiplication, and derivation using linked lists. The project requires
the representation of each polynomial in a linked list, where each node contains
information about the coefficient, exponent, and link to the next term. The project
consists of four modules, each for a specific polynomial operation. The successful
implementation of this project requires knowledge of creating and using linked
lists, pointers, self-referential structures, and polynomial operations.
INDEX

S.NO TITLE PAGE NO

1 Introduction <6>

2 Aim of the Project <7>

2.1 Advantages & Disadvantages <7>

2.2 Future Implementation <8>

3 Software & Hardware Details <9>

4 Algorithm <10 –11>

5 Flowchart <12-15>

6 Implementation <16-29>

7 Results and Screenshots <30-31>

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

Processor : AMD RYZEN 7 6800H (or) Intel Core i7-12700H


ALGORITHM

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.

Return 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.

Return 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.

Return the output linked list.

Polynomial Derivation:

Define a function that takes a linked list representing a polynomial as input.

Initialize a new linked list to represent the derivative of the polynomial.

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.

Return the output linked list.


FLOWCHART
IMPLEMENTATION
#include<stdio.h>

#include<stdlib.h>

struct node {

int coef,expo;

struct node *next;

}*head=NULL,*head2=NULL,*mul1=NULL;

struct neekuenduk {

int coef;

int expo;

struct neekuenduk *next;

}*headmul=NULL;

void mul();

void add();

void sub();

void polynomial_1();

void polynomial_2();

void derivation();

void choice()

printf("\n1. Store the values of 1st Polynomial\n");

printf("2. Store the values of 2nd Polynomial\n");

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;

printf("Enter how many values do you want to enter: ");

scanf("%d",&f);

for(i=0;i<f;i++)

struct node *new;

struct node *temp;

new=(struct node *)malloc(sizeof(struct node));

printf("\nEnter Coeff: ");

scanf("%d",&new->coef);

printf("\nEnter Exponent: ");

scanf("%d",&new->expo);

new->next=NULL;

if (head==NULL)

head=new;

}
else

temp=head;

if (temp->expo>new->expo)

while ( temp->expo>new->expo && temp->next!=NULL)

temp=temp->next;

temp->next=new;

else

new->next=head;

head=new;

void polynomial_2()

int f,i;

printf("Enter how many values do you want to enter: ");

scanf("%d",&f);

for(i=0;i<f;i++)
{

struct node *new2;

struct node *temp2;

new2=(struct node *)malloc(sizeof(struct node));

printf("\nEnter Coeff: ");

scanf("%d",&new2->coef);

printf("\nEnter Exponent: ");

scanf("%d",&new2->expo);

new2->next=NULL;

if (head2==NULL)

head2=new2;

else

temp2=head2;

if (temp2->expo>new2->expo)

while ( temp2->expo>new2->expo && temp2->next!=NULL)

temp2=temp2->next;

temp2->next=new2;

else

new2->next=head2;
head2=new2;

void add()

struct node *temp2;

struct node *temp;

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;

if (temp->next==NULL && temp->expo!=0 && temp2->expo!=0)

printf("%dx^%d",temp->coef+temp2->coef,temp->expo);

if (temp->expo==0 && temp2->expo==0)

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()

struct node *temp2;

struct node *temp;

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;

if (temp->next==NULL && temp->expo!=0 && temp2->expo!=0)

printf("%dx^%d",temp->coef-temp2->coef,temp->expo);

if (temp->expo==0 && temp2->expo==0)

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()

struct node *temp1=head;

struct node *temp2=head2;

while(temp1!=NULL)

temp2=head2;

while(temp2!=NULL)

struct node *new;

new=(struct node *)malloc(sizeof(struct node));

new->coef=temp1->coef*temp2->coef;

new->expo=temp1->expo+temp2->expo;

new->next=NULL;

temp2=temp2->next;

if(mul1==NULL)

mul1=new;

else

struct node *temp0=mul1;

while(temp0->next!=NULL)

temp0=temp0->next;

}
temp0->next=new;

temp1=temp1->next;

//hi

struct neekuenduk *new1,*temp20;

new1=(struct neekuenduk*)malloc(sizeof(struct neekuenduk));

new1->coef=0;

new1->expo=4;

new1->next=NULL;

headmul=new1;

temp20=new1;

// hi

struct neekuenduk *new2;

new2=(struct neekuenduk*)malloc(sizeof(struct neekuenduk));

temp20->next=new2;

temp20=new2;

new2->coef=0;

new2->expo=3;

new2->next=NULL;

//hi

struct neekuenduk *new3;

new3=(struct neekuenduk*)malloc(sizeof(struct neekuenduk));

temp20->next=new3;

temp20=new3;

new3->coef=0;

new3->expo=2;
new3->next=NULL;

//hi

struct neekuenduk *new4;

new4=(struct neekuenduk*)malloc(sizeof(struct neekuenduk));

temp20->next=new4;

temp20=new4;

new4->coef=0;

new4->expo=1;

new4->next=NULL;

struct node *naestam=mul1;

struct neekuenduk *temp4=headmul,*temp3=temp4->next;

struct neekuenduk *temp22=temp3->next,*temp11=temp22->next;

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;

struct neekuenduk *temp600=headmul;

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()

struct node *temp=head;

struct node *temp1=head2;

printf("Derivation of 1st Equation: ");

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);

printf("Derivation of 2nd Equation: ");

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

This is a C program that implements some polynomial operations like adding,


subtracting, multiplying and deriving two polynomials.

Here is how the program works:

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.

The implementation of linked list applications in polynomial operations is an important


project for students to gain knowledge and experience in using linked lists and pointers.
By implementing this project, students can learn how to use self-referential structures
to store and manipulate polynomial terms efficiently. They will also learn about
polynomial operations such as addition, subtraction, multiplication, and derivation, and
how to implement them using linked lists.

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.

In conclusion, the implementation of linked list applications in polynomial operations is


an excellent project for students to gain practical knowledge and experience in using
linked lists and pointers. It helps them to develop their problem-solving and
programming skills, which are essential for their future career in various fields.

You might also like