SlideShare a Scribd company logo
LINKED LIST
INTRODUCTION

The linked list is a very effective and efficient dynamic
data structure

Data items can be stored anywhere in memory in a
scattered manner

To maintain the specific sequence of these data items
we need to maintain link(s) with successor (and/ or
predecessor)

It is called as a linked list
INTRODUCTION

A linked list is an ordered collection of data in whi
each element contains minimum two values, da
and link(s) to its successor (and/ or predecessor)

The list with one link field using which every eleme
is associated to either its predecessor or successor
called as singly linked list

In a linked list, before adding any element to the li
memory space for that node must be allocated

A link is kept with each item to the next item in the li
Fig: 2 (a): A linked list of n elements
Fig: 2 (b) : A linked list of weekdays

Each node of the linked list has minimum two elements :
The data member(s) being stored in the list
A pointer or link to the next element in the list

The last node in the list contains a NULL (or -1) pointer to
indicate that it is the end or tail of the list
Linked Organization

Element can be placed anywhere in the memory

Dynamic allocation (size need not be known in advance)
i.e. space allocation as per need can be done during
execution.

As objects are not placed at fixed distance apart, random
access to elements is not possible.

Insertion and deletion of objects do not require any data
shifting.

Space efficient for large objects and large quantity with
often insertions and deletions

Each element in general is a collection of data and a link.
At least one link field is must.

Every element keeps address of its successor element in
a link field.

Some more operations, which are based on above basic
operations are:

Searching a node

Updating node.

Printing the node or list.

Counting length of the list.

Reverse the list.

Sort the list using pointer manipulation.

Concatenate two lists.

Merge two-sorted list into third sorted list
The Linked List ADT

Data Structure of Node

Insertion of a Node

Linked List Traversal
Non-Recursive Method
Recursive Traversal Method
Types of Linked List
 Singly linked list
 Doubly linked list
 Circular linked list
Singly Linked List

A linked list in which every node has one link field,
to provide information about where the next node of
list is, is called as singly linked list
Doubly linked list

In doubly linked list, each node has two link fields to
store information about who is the next and also
about who is ahead of the node

Hence each node has knowledge of its successor and
also its predecessor.

In doubly linked list, from every node the list can be
traversed in both the directions.
Circular linked list

For example, consider a singly linked list.

Given a pointer A to a node in a linear list, we cannot
reach any of the nodes that precede the node to
which A is pointing.

This disadvantage can be overcome by making a
small change. This change is without any additional
data structure.

The link field of last node is set to NULL in linear list
to mark end of list. This link field of last node can be
set to point first node rather than NULL. Such a linked
list is called a circular linked list.
Although a linear linked list is a useful and popular data
structure, it has some shortcomings.
Circular linked list
class node
{
int data; // data
node* next; // pointer to next
public:
node* create();
void display(node*);
node* beg_del(node*);
node* end_del(node*);
node* mid_del(node*);
node* beg_add(node*);
node* end_add(node*);
node* mid_add(node*);
node* total(node*);
};
node* node::create()
{
node* head,*p;
head=NULL;
cout<<"Enter the number of members"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
if(head==NULL)
{
head=new node;
cout<<"Enter the roll number and name of the
member"<<endl;
cin>>head->rno;
cin>>head->name;
head->next=NULL;
p=head;
}
else
{
p->next=new node;
p=p->next;
cout<<"Enter the roll number and name of the
member"<<endl;
cin>>p->rno;
cin>>p->name;
p->next=NULL;
}
void node::display(node *head)
{
for(p=head;p!=NULL;p=p->next)
{
cout<<"Roll No:"<<p->rno<<"
";
cout<<"Name:"<<p-
>name<<endl;
}
}

Inserting a new node

Possible cases of InsertNode
1. Insert into an empty list
2. Insert in front
3. Insert at back
4. Insert in middle

But, in fact, only need to handle two cases
1. Insert as the first node (Case 1 and Case 2)
2. Insert in the middle or at the end of the list (Case 3 and
Case 4)
node* node::beg_add(node* head)
{
p=new node;
cout<<"Enter the roll number and name of the member"<<endl;
cin>>p->rno;
cin>>p->name;
p->next=NULL;
p->next=head;
head=p;
return head;
}
node* node::end_add(node* head)
{
p=new node;
cout<<"Enter the roll number and name of the
member"<<endl;
cin>>p->rno;
cin>>p->name;
p->next=NULL;
for(q=head;q->next!=NULL;q=q->next);
q->next=p;
return head;
}
node* node::mid_add(node* head)
{
p=new node;
cout<<"Enter the roll number and name of the
member"<<endl;
cin>>p->rno;
cin>>p->name;
p->next=NULL;
cout<<"Enter the value after which you want to insert
the member";
cin>>y;
for(q=head;q->rno==y && q!=NULL;q=q->next);
if(q==NULL)
{
cout<<"Data not found";
}
else
{
p->next=q->next;
q->next=p;
}

Deleting node

Possible cases of InsertNode
1. Delete from front
2. Delete from back
3. Delete middle element
node* node::beg_del(node* head)
{
p=head;
head=head->next;
delete p;
return head;
}
node* node::end_del(node* head)
{
for(p=head;p->next->next!=NULL;p=p->next);
q=p->next;
p->next=NULL;
delete q;
}
node* node::mid_del(node* head)
{
cout<<"Enter the roll number of the member which you want to
delete";
cin>>y;
if( head==NULL)
{
cout<<"linked list is empty";
return(head);
}
for(p=head;p->next->rno==y && p->next!=NULL;p=p->next)
{
p->next=p->next->next;
delete p->next;
}
return head;
}
Polynomial Manipulations
A node will have 3 fields, which represent
the coefficient and exponent of a term and a
pointer to the next term

For instance, the polynomial, say A = 6x7 + 3x5 + 4x3
+ 12 would be stored as :
Operations on Polynomials
Polynomial evaluation
Polynomial addition
Multiplication of two polynomials
Representation of sparse matrix using
linked list
Linked list implementation of the stack
Generalized linked list
Garbage Collection : An
Application Of Linked List

Overflow : Sometimes new data node is to be
inserted into data structure but there is no
available space i.e. free-pool is empty. This situation is
called overflow

Underflow : This refers to situation where
programmer wants to delete a node from empty
list

For good memory utilization, operating system
periodically collects all the free blocks and inserts
into free-pool

Any technique that does this collection is called
garbage collection
Summary

There are two implementation of linked linear list; array and pointers

There is a need is of such a data structure which can dynamically
shrink and grow

Hence the popular implementation us using pointers and dynamic
memory management

Singly linked lists are useful data structures, especially if you need to
automatically allocate and de-allocate space in a list

The basic operation are create list, transverse the list, insert and delete
a node

There are two variation of linked list singly and doubly linked list. Both
linked list can be circular lists

The linked could be with or without head node. Head node is used to
store some information about the list, so that it can be accessed without
traversing the same
Summary

In doubly linked list, each node has two link fields to store information
about who is the next and also about who is ahead of the node

Hence each node has knowledge of its successor and also its
predecessor.

In doubly linked list, from every node the list can be traversed in both
the directions.

Information could be like total number of nodes in the list and similarly
any other Linked list is the most popular data structure used. It has
many application such as process queue, print queue, garbage
collection etc
l Sequential organisation

Provides static allocation, which means space allocation is
done by compiler once cannot be changed during execution
and size has to be known in advance.

As individual objects are stored at fixed distance apart, we can
access any element randomly.

Insertion and deletion of objects in between the list requires a lot
of data movement.

Space inefficient for large objects and large quantity with often
insertions and deletions

Element need not know/store keep address of its successive
element.

More Related Content

DOCX
Linked list.docx
PPT
Linked List
PPTX
csc211_lecture_21.pptx
PPT
Link list using array in Data structure amd algorithms
PDF
Linked list (introduction) 1
PPT
Algo>ADT list & linked list
PPTX
Datastucture-Unit 4-Linked List Presentation.pptx
PPTX
Linked Lists, Single Linked list and its operations
Linked list.docx
Linked List
csc211_lecture_21.pptx
Link list using array in Data structure amd algorithms
Linked list (introduction) 1
Algo>ADT list & linked list
Datastucture-Unit 4-Linked List Presentation.pptx
Linked Lists, Single Linked list and its operations

Similar to DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx (20)

PPTX
Data Structures_Linked List
PPT
Linked list1.ppt
PPTX
1.3 Linked List.pptx
PPT
Unit ii(dsc++)
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
PPTX
Linked list
PPTX
LinkedLists important things DS peractie.pptx
PPTX
linked list_MODULE 3.pptx ppt on the linked list
PPTX
Deletion from single way linked list and search
PPTX
Linked List in Data Structure
PPTX
Linked list
PPT
Lecture 3 List of Data Structures & Algorithms
PPTX
Data Structures-UNIT Four_Linked_List.pptx
PPTX
Linked List Representation of a Linked List.pptx
PPTX
Linked List.pptx
PPTX
linkedlistforslideshare-210123143943.pptx
PPT
linked_lists.ppt linked_lists linked_lists
PDF
Link list
PPTX
Module 3 Dara structure notes
PPT
Fundamentals of data structures
Data Structures_Linked List
Linked list1.ppt
1.3 Linked List.pptx
Unit ii(dsc++)
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked list
LinkedLists important things DS peractie.pptx
linked list_MODULE 3.pptx ppt on the linked list
Deletion from single way linked list and search
Linked List in Data Structure
Linked list
Lecture 3 List of Data Structures & Algorithms
Data Structures-UNIT Four_Linked_List.pptx
Linked List Representation of a Linked List.pptx
Linked List.pptx
linkedlistforslideshare-210123143943.pptx
linked_lists.ppt linked_lists linked_lists
Link list
Module 3 Dara structure notes
Fundamentals of data structures
Ad

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
PPT on Performance Review to get promotions
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Sustainable Sites - Green Building Construction
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
web development for engineering and engineering
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
DOCX
573137875-Attendance-Management-System-original
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Construction Project Organization Group 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT on Performance Review to get promotions
Internet of Things (IOT) - A guide to understanding
Safety Seminar civil to be ensured for safe working.
Sustainable Sites - Green Building Construction
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mechanical Engineering MATERIALS Selection
UNIT 4 Total Quality Management .pptx
web development for engineering and engineering
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Fundamentals of safety and accident prevention -final (1).pptx
573137875-Attendance-Management-System-original
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Model Code of Practice - Construction Work - 21102022 .pdf
Construction Project Organization Group 2.pptx
Ad

DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx

  • 2. INTRODUCTION  The linked list is a very effective and efficient dynamic data structure  Data items can be stored anywhere in memory in a scattered manner  To maintain the specific sequence of these data items we need to maintain link(s) with successor (and/ or predecessor)  It is called as a linked list
  • 3. INTRODUCTION  A linked list is an ordered collection of data in whi each element contains minimum two values, da and link(s) to its successor (and/ or predecessor)  The list with one link field using which every eleme is associated to either its predecessor or successor called as singly linked list  In a linked list, before adding any element to the li memory space for that node must be allocated  A link is kept with each item to the next item in the li
  • 4. Fig: 2 (a): A linked list of n elements Fig: 2 (b) : A linked list of weekdays
  • 5.  Each node of the linked list has minimum two elements : The data member(s) being stored in the list A pointer or link to the next element in the list  The last node in the list contains a NULL (or -1) pointer to indicate that it is the end or tail of the list
  • 6. Linked Organization  Element can be placed anywhere in the memory  Dynamic allocation (size need not be known in advance) i.e. space allocation as per need can be done during execution.  As objects are not placed at fixed distance apart, random access to elements is not possible.  Insertion and deletion of objects do not require any data shifting.  Space efficient for large objects and large quantity with often insertions and deletions  Each element in general is a collection of data and a link. At least one link field is must.  Every element keeps address of its successor element in a link field.
  • 7.  Some more operations, which are based on above basic operations are:  Searching a node  Updating node.  Printing the node or list.  Counting length of the list.  Reverse the list.  Sort the list using pointer manipulation.  Concatenate two lists.  Merge two-sorted list into third sorted list
  • 8. The Linked List ADT  Data Structure of Node  Insertion of a Node  Linked List Traversal Non-Recursive Method Recursive Traversal Method
  • 9. Types of Linked List  Singly linked list  Doubly linked list  Circular linked list
  • 10. Singly Linked List  A linked list in which every node has one link field, to provide information about where the next node of list is, is called as singly linked list
  • 11. Doubly linked list  In doubly linked list, each node has two link fields to store information about who is the next and also about who is ahead of the node  Hence each node has knowledge of its successor and also its predecessor.  In doubly linked list, from every node the list can be traversed in both the directions.
  • 12. Circular linked list  For example, consider a singly linked list.  Given a pointer A to a node in a linear list, we cannot reach any of the nodes that precede the node to which A is pointing.  This disadvantage can be overcome by making a small change. This change is without any additional data structure.  The link field of last node is set to NULL in linear list to mark end of list. This link field of last node can be set to point first node rather than NULL. Such a linked list is called a circular linked list. Although a linear linked list is a useful and popular data structure, it has some shortcomings.
  • 14. class node { int data; // data node* next; // pointer to next public: node* create(); void display(node*); node* beg_del(node*); node* end_del(node*); node* mid_del(node*); node* beg_add(node*); node* end_add(node*); node* mid_add(node*); node* total(node*); };
  • 15. node* node::create() { node* head,*p; head=NULL; cout<<"Enter the number of members"<<endl; cin>>n; for(i=0;i<n;i++) { if(head==NULL) { head=new node; cout<<"Enter the roll number and name of the member"<<endl; cin>>head->rno; cin>>head->name; head->next=NULL; p=head; } else { p->next=new node; p=p->next; cout<<"Enter the roll number and name of the member"<<endl; cin>>p->rno; cin>>p->name; p->next=NULL; }
  • 16. void node::display(node *head) { for(p=head;p!=NULL;p=p->next) { cout<<"Roll No:"<<p->rno<<" "; cout<<"Name:"<<p- >name<<endl; } }
  • 17.  Inserting a new node  Possible cases of InsertNode 1. Insert into an empty list 2. Insert in front 3. Insert at back 4. Insert in middle  But, in fact, only need to handle two cases 1. Insert as the first node (Case 1 and Case 2) 2. Insert in the middle or at the end of the list (Case 3 and Case 4)
  • 18. node* node::beg_add(node* head) { p=new node; cout<<"Enter the roll number and name of the member"<<endl; cin>>p->rno; cin>>p->name; p->next=NULL; p->next=head; head=p; return head; } node* node::end_add(node* head) { p=new node; cout<<"Enter the roll number and name of the member"<<endl; cin>>p->rno; cin>>p->name; p->next=NULL; for(q=head;q->next!=NULL;q=q->next); q->next=p; return head; }
  • 19. node* node::mid_add(node* head) { p=new node; cout<<"Enter the roll number and name of the member"<<endl; cin>>p->rno; cin>>p->name; p->next=NULL; cout<<"Enter the value after which you want to insert the member"; cin>>y; for(q=head;q->rno==y && q!=NULL;q=q->next); if(q==NULL) { cout<<"Data not found"; } else { p->next=q->next; q->next=p; }
  • 20.  Deleting node  Possible cases of InsertNode 1. Delete from front 2. Delete from back 3. Delete middle element
  • 21. node* node::beg_del(node* head) { p=head; head=head->next; delete p; return head; } node* node::end_del(node* head) { for(p=head;p->next->next!=NULL;p=p->next); q=p->next; p->next=NULL; delete q; }
  • 22. node* node::mid_del(node* head) { cout<<"Enter the roll number of the member which you want to delete"; cin>>y; if( head==NULL) { cout<<"linked list is empty"; return(head); } for(p=head;p->next->rno==y && p->next!=NULL;p=p->next) { p->next=p->next->next; delete p->next; } return head; }
  • 23. Polynomial Manipulations A node will have 3 fields, which represent the coefficient and exponent of a term and a pointer to the next term
  • 24.  For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 + 12 would be stored as :
  • 25. Operations on Polynomials Polynomial evaluation Polynomial addition Multiplication of two polynomials Representation of sparse matrix using linked list Linked list implementation of the stack Generalized linked list
  • 26. Garbage Collection : An Application Of Linked List  Overflow : Sometimes new data node is to be inserted into data structure but there is no available space i.e. free-pool is empty. This situation is called overflow  Underflow : This refers to situation where programmer wants to delete a node from empty list  For good memory utilization, operating system periodically collects all the free blocks and inserts into free-pool  Any technique that does this collection is called garbage collection
  • 27. Summary  There are two implementation of linked linear list; array and pointers  There is a need is of such a data structure which can dynamically shrink and grow  Hence the popular implementation us using pointers and dynamic memory management  Singly linked lists are useful data structures, especially if you need to automatically allocate and de-allocate space in a list  The basic operation are create list, transverse the list, insert and delete a node  There are two variation of linked list singly and doubly linked list. Both linked list can be circular lists  The linked could be with or without head node. Head node is used to store some information about the list, so that it can be accessed without traversing the same
  • 28. Summary  In doubly linked list, each node has two link fields to store information about who is the next and also about who is ahead of the node  Hence each node has knowledge of its successor and also its predecessor.  In doubly linked list, from every node the list can be traversed in both the directions.  Information could be like total number of nodes in the list and similarly any other Linked list is the most popular data structure used. It has many application such as process queue, print queue, garbage collection etc
  • 29. l Sequential organisation  Provides static allocation, which means space allocation is done by compiler once cannot be changed during execution and size has to be known in advance.  As individual objects are stored at fixed distance apart, we can access any element randomly.  Insertion and deletion of objects in between the list requires a lot of data movement.  Space inefficient for large objects and large quantity with often insertions and deletions  Element need not know/store keep address of its successive element.