Operations on linked list
Organization of data and theOrganization of data and the
relationship among its members isrelationship among its members is
called as data structurecalled as data structure
Data Structure
Operations on linked list
Why we need Linked List?
What are the problems with Arrays?
Size is fixed
Array Items are stored contiguously
Insertions and deletion at particular position is
complex
Why Linked list ?
 Size is not fixed
 Data can be stored at any place
 Insertions and deletions are simple and faster
What are Linked ListsWhat are Linked Lists
A linked list is a linear data
structure.
Nodes make up linked lists.
Nodes are structures made
up of data and a pointer to
another node.
Usually the pointer is called
next.
 A linked list consists of:
◦ A sequence of nodes
6
a b c d
Each node contains a value
and a link (pointer or reference) to some other node
The last node contains a null link
The list may (or may not) have a header
myList
Linked List Types
 Singly Linked list
 Doubly linked lists
 Circular singly linked list
 Circular doubly linked lists
 Each node has only one link part
 Each link part contains the address of the next
node in the list
 Link part of the last node contains NULL value
which signifies the end of the node
10
1000
1000
2000
200015 NULL20
4000
Singly Linked List
Each node points the next node . It is a
one way list.
First
10 15 20
Circular Singly Linked List
Last node contains the address of the first node
First
Doubly Linked list
Contains the address of previous node and
next node
NULL
2000 30001000
10 15 202000 1000 2000 NULL3000
First
Circular Doubly Linked list
Contains the address of first node and last
node
3000
2000 30001000
10 15 202000 1000 2000 10003000
Operations on Linked List
Creation of the linked list
Insertion of nodes
Traversal of the linked list
Search a specific node in the linked list
Deletion of a node in the linked list
Creation of the linked list
Creation of a LL is a special case of insertion, i.e. insertion into an
empty list.
If the value of start is null, it implies that there are no nodes in the list.
Creation is a two step process
a)Creating the new node
b)Storing the address of the new node in the start
10 20 30 45 X
Next
Creation of the Linked List
Start
Info Next
 There are three ways to insert a node into the list.
 Insertion at the beginning
 Insertion at the end
 Insertion after a particular node
There are two steps to be followed:-
a) Make the next pointer of the node point towards
the first node of the list
b) Make the start pointer point towards this new node
 If the list is empty simply make the start pointer
point towards the new node;
Operations on linked list
Algorithm to Insert an Element from the front
INSERT(Start,data)
1.Allocate memory to New
2. Set NewInfo=data
3.NewNext=start
4.Start=New
5.Return Start
Here we simply need to make the next pointer
of the last node point to the new node
Here we again need to do 2 steps :-
 Make the next pointer of the node to be inserted
point to the next node of the node after which you
want to insert the node
 Make the next pointer of the node after which the
node is to be inserted, point to the node to be
inserted
Operations on linked list
Traversal of a LL means to traverse each node of the list,
and visiting each node exactly once.
Algorithm:
1.Set Ptr to Start.
2.Repeat steps 3 and 4 until Ptr is not equal to Null.
3.Print the Info part of each node to which Ptr is pointing
currently.
4.Advance the pointer Ptr so that it points to the next node.
5.End
a b c d
start Info
NextPtr
Logic using C
Traverse()
{
Struct node *ptr;
Ptr=start;
While(ptr)
{
Print(“The current node %s”, ptritem-no);
Ptr=ptrnext;
}
}
 Searching involves finding the required element in the list
 We can use various techniques of searching like linear search or
binary search where binary search is more efficient in case of
Arrays
 But in case of linked list since random access is not available it
would become complex to do binary search in it
 We can perform simple linear search traversal
Algorithm
1. Set Ptr to start
2. Input the item to be searched
3. While Ptr!=null do steps 4 and 5
4. Compare the item with the given value. If they are
same ,exit from the loop and goto step 6, else
5. Set Ptr to next node
6. Report that the data found in the list .Otherwise it
doesn’t exist .
In linear search each node is traversed till the data in
the node matches with the required value
void search(int x)
{
node*temp=start;
while(temp!=NULL)
{
if(temp->data==x)
{
Print “FOUND ”;
break;
}
temp=temp->next;
}
}
Deletion of a node is carried out in two steps viz,
a) Logical deletion pointer shuffling in order to remove the
links
b) Physical deletion  release the memory occupied using
free() function
Here also we have three cases:-
 Deleting the first node
 Deleting the last node
 Deleting the intermediate node
Here we apply 3 steps:-
 Making the start pointer point towards the 2nd
node
 Free the space associated with first node
 Operating system collects the free space of the memory and
use it with available free space.
The process is given by
 Temp=start;
 Start=startnext;
 Free(temp)
threetwoone
start
Here we apply 2 steps:-
 Traverse the list to find the last node.
 Deleting the last node via delete keyword
node3node2node1
start
 Traverse the list to find the node to be deleted. Search is used
for this purpose. Refer that as curr_ptr.
 Then delete that node by setting the pointers as
Prevnext=curr_ptrnext;
 Then physical deletion is achieved by free().
node1 node2 node3
To be deleted
The node in DLL may be deleted
 At the beginning
 At the end
 At any desired position
Steps to be followed
1. If the list is empty display underflow message
2. If a single node exists, set both the pointers as Null. Else if it is the first
node, then delete it and update the pointers.
3. Else if, it is the last node, then delete it and update the right pointer.
4. Restore the deleted node to the free list
 Generalized list A is a finite sequence of n>=0 elements.
 A=(α0 ….. α n-1 ), here A  name of the list and α0 ….. α n-1 represents
the elements. It is either atom or a list.
 Name is given by capital letter and elements by small case.
Ex:
1. D=() the null (or) empty list and its length is zero
2. A=(a(b,c)) a list of length 2
3. B=(A,A,())  a list of length 3, the third one is null.
4. C=(a,c)  a recursive list of length 2, c corresponds to the infinite
list.
Linked stack
 In linked stack we can easily add a node at the top
or delete a node from the top.
 It is similar to push and pop the elements.
 A stack can be accessed only through its top
element,and a linked list can be accessed by
using the pointer to its first element.
6 9 12 15
Top
X
Null
Linked Stack
 Linked list representations of queue are easy to
handle.
 We need two pointers namely Front and Rear.
 Front represents the beginning of the queue and
rear represents the end of the queue.
 Q.Rear=null indicates the queue is empty.
6 9 12 15
Front
X
Rear
Null
Linked Queue
9 12 15 X
Null
Header Linked List
Header Node
The header for a LL is a pointer variable that locates the beginning of the
list
 HLL is a LL which always contains a special node
called the header node.
 Header node is at the beginning of the list.
 Dummy nodes placed as the first node of a list which
is used to simplify linked list processing.
 It may or may not contain meaningful information.
 It does not represents an item in the list.
 The info portion of the such a header node might be
unused.
 It is used to keep the global information about the
entire list.
Operations on linked list

More Related Content

PDF
Binary search tree operations
PPTX
Queue
PPT
Data Structure and Algorithms Linked List
PPTX
Binary Search Tree in Data Structure
PPTX
PPT
linked list
PPT
Linked list
PPT
Linked lists
Binary search tree operations
Queue
Data Structure and Algorithms Linked List
Binary Search Tree in Data Structure
linked list
Linked list
Linked lists

What's hot (20)

PDF
linked lists in data structures
PPT
B trees in Data Structure
PPTX
Linked list
PPTX
CIRCULAR LINKED LIST _
PDF
Tree and binary tree
PPTX
Binary search
PDF
Binary tree
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PDF
Data Structures (BE)
PPTX
Linked List
PPTX
Threaded Binary Tree.pptx
PPT
Binary tree
PPTX
Asymptotic Notation
PPTX
Graph traversals in Data Structures
PPTX
single linked list
PDF
Searching and Sorting Techniques in Data Structure
PPTX
Data Structures - Lecture 7 [Linked List]
PPTX
Doubly & Circular Linked Lists
PPT
Hashing PPT
linked lists in data structures
B trees in Data Structure
Linked list
CIRCULAR LINKED LIST _
Tree and binary tree
Binary search
Binary tree
Trees, Binary Search Tree, AVL Tree in Data Structures
Data Structures (BE)
Linked List
Threaded Binary Tree.pptx
Binary tree
Asymptotic Notation
Graph traversals in Data Structures
single linked list
Searching and Sorting Techniques in Data Structure
Data Structures - Lecture 7 [Linked List]
Doubly & Circular Linked Lists
Hashing PPT
Ad

Viewers also liked (19)

PPT
Lec6 mod linked list
PPS
07 ds and algorithm session_10
PPS
04 ds and algorithm session_05
PPS
05 ds and algorithm session_07
PPTX
Linked Lists
PPTX
Applications of data structures
PPT
Sparse Matrix and Polynomial
PDF
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
PPTX
Sparse matrices
PPSX
Data Structure (Dynamic Array and Linked List)
PPT
linked list
PPTX
Linked list
PPTX
Data structure and its types
PDF
Top10 Innovative Ideas You Haven't Heard of in the Developing World
PPTX
Data Structure
PPT
Lecture 1 data structures and algorithms
PPT
DATA STRUCTURES
Lec6 mod linked list
07 ds and algorithm session_10
04 ds and algorithm session_05
05 ds and algorithm session_07
Linked Lists
Applications of data structures
Sparse Matrix and Polynomial
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Sparse matrices
Data Structure (Dynamic Array and Linked List)
linked list
Linked list
Data structure and its types
Top10 Innovative Ideas You Haven't Heard of in the Developing World
Data Structure
Lecture 1 data structures and algorithms
DATA STRUCTURES
Ad

Similar to Operations on linked list (20)

PPTX
DS_LinkedList.pptx
PPTX
Linked List in Data Structure
PDF
ds-lecture-4-171012041008 (1).pdf
PPTX
linked list in data structure
PPT
Linked List
PPT
Link list using array in Data structure amd algorithms
PPTX
Linked lists a
PPTX
Engineering.CSE.DataStructure.Linkedlist.notes
PPTX
VCE Unit 02 (1).pptx
PPTX
Linked list (1).pptx
PPTX
Data Structures Introduction & Linear DS
PPTX
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
PDF
Linked Lists.pdf
PPTX
1.3 Linked List.pptx
PPT
linked_lists.ppt linked_lists linked_lists
PPTX
Linked list
PPT
ANOITO2341988888888888888888888885555.ppt
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
PPT
PPTX
linkedlist-130914084342-phpapp02.pptx
DS_LinkedList.pptx
Linked List in Data Structure
ds-lecture-4-171012041008 (1).pdf
linked list in data structure
Linked List
Link list using array in Data structure amd algorithms
Linked lists a
Engineering.CSE.DataStructure.Linkedlist.notes
VCE Unit 02 (1).pptx
Linked list (1).pptx
Data Structures Introduction & Linear DS
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
Linked Lists.pdf
1.3 Linked List.pptx
linked_lists.ppt linked_lists linked_lists
Linked list
ANOITO2341988888888888888888888885555.ppt
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
linkedlist-130914084342-phpapp02.pptx

Recently uploaded (20)

PDF
Antihypertensive Drugs by Dr. Haseeba Talat (14.03.2020).pdf
DOCX
lesson plan on learning disabilities in children
PDF
The scientific heritage No 167 (167) (2025)
PDF
XUE: The CO2-rich terrestrial planet-forming region of an externally irradiat...
PPTX
Morphology of Bacteria & Structure of Bacterial Cell
PPTX
Drug Chemistry, Absorption and Distribution
PDF
Biologics and Monoclonal Antibodies pdf
PDF
Biologics and Monoclonal Antibodies_Part 2 pdf
PPTX
DiffErent Techniques of Analysis (Qualitative & Quantitative).pptx
PPTX
ENDOCRINE_SYSTEM_ANATOMY_AND_PHYSIOLOGY.pptx
DOCX
atomic physics ookikkkkkkkkkkkkkkkkkkkkd
PPTX
GMO, genetic engineering,geniticaly modified organisms
PPTX
Earth-and-Life-Pieces-of-Evidence-Q2.pptx
PDF
Sujay Rao Mandavilli public profile September 2025.pdf
PDF
Environmental chemistry and policies employed by countries to save earth
PPTX
IMPROVEMENT IN FOOD AND RESOURCES Class 9th NCERT .pptx
PPTX
URINARY SYSTEM.BY Dr. DEEPAK KUMAR CHOUDHARY
PDF
CITOQUINAS EN ORTODONCIA BIOLOGIA DEL MOVIMIENTO
PPTX
Epithelial Tissues and Glands.pptx slide show
PPTX
history of Pharmacology-1.pptx .
Antihypertensive Drugs by Dr. Haseeba Talat (14.03.2020).pdf
lesson plan on learning disabilities in children
The scientific heritage No 167 (167) (2025)
XUE: The CO2-rich terrestrial planet-forming region of an externally irradiat...
Morphology of Bacteria & Structure of Bacterial Cell
Drug Chemistry, Absorption and Distribution
Biologics and Monoclonal Antibodies pdf
Biologics and Monoclonal Antibodies_Part 2 pdf
DiffErent Techniques of Analysis (Qualitative & Quantitative).pptx
ENDOCRINE_SYSTEM_ANATOMY_AND_PHYSIOLOGY.pptx
atomic physics ookikkkkkkkkkkkkkkkkkkkkd
GMO, genetic engineering,geniticaly modified organisms
Earth-and-Life-Pieces-of-Evidence-Q2.pptx
Sujay Rao Mandavilli public profile September 2025.pdf
Environmental chemistry and policies employed by countries to save earth
IMPROVEMENT IN FOOD AND RESOURCES Class 9th NCERT .pptx
URINARY SYSTEM.BY Dr. DEEPAK KUMAR CHOUDHARY
CITOQUINAS EN ORTODONCIA BIOLOGIA DEL MOVIMIENTO
Epithelial Tissues and Glands.pptx slide show
history of Pharmacology-1.pptx .

Operations on linked list

  • 2. Organization of data and theOrganization of data and the relationship among its members isrelationship among its members is called as data structurecalled as data structure Data Structure
  • 4. Why we need Linked List? What are the problems with Arrays? Size is fixed Array Items are stored contiguously Insertions and deletion at particular position is complex Why Linked list ?  Size is not fixed  Data can be stored at any place  Insertions and deletions are simple and faster
  • 5. What are Linked ListsWhat are Linked Lists A linked list is a linear data structure. Nodes make up linked lists. Nodes are structures made up of data and a pointer to another node. Usually the pointer is called next.
  • 6.  A linked list consists of: ◦ A sequence of nodes 6 a b c d Each node contains a value and a link (pointer or reference) to some other node The last node contains a null link The list may (or may not) have a header myList
  • 7. Linked List Types  Singly Linked list  Doubly linked lists  Circular singly linked list  Circular doubly linked lists
  • 8.  Each node has only one link part  Each link part contains the address of the next node in the list  Link part of the last node contains NULL value which signifies the end of the node
  • 9. 10 1000 1000 2000 200015 NULL20 4000 Singly Linked List Each node points the next node . It is a one way list. First
  • 10. 10 15 20 Circular Singly Linked List Last node contains the address of the first node First
  • 11. Doubly Linked list Contains the address of previous node and next node NULL 2000 30001000 10 15 202000 1000 2000 NULL3000 First
  • 12. Circular Doubly Linked list Contains the address of first node and last node 3000 2000 30001000 10 15 202000 1000 2000 10003000
  • 13. Operations on Linked List Creation of the linked list Insertion of nodes Traversal of the linked list Search a specific node in the linked list Deletion of a node in the linked list
  • 14. Creation of the linked list Creation of a LL is a special case of insertion, i.e. insertion into an empty list. If the value of start is null, it implies that there are no nodes in the list. Creation is a two step process a)Creating the new node b)Storing the address of the new node in the start
  • 15. 10 20 30 45 X Next Creation of the Linked List Start Info Next
  • 16.  There are three ways to insert a node into the list.  Insertion at the beginning  Insertion at the end  Insertion after a particular node
  • 17. There are two steps to be followed:- a) Make the next pointer of the node point towards the first node of the list b) Make the start pointer point towards this new node  If the list is empty simply make the start pointer point towards the new node;
  • 19. Algorithm to Insert an Element from the front INSERT(Start,data) 1.Allocate memory to New 2. Set NewInfo=data 3.NewNext=start 4.Start=New 5.Return Start
  • 20. Here we simply need to make the next pointer of the last node point to the new node
  • 21. Here we again need to do 2 steps :-  Make the next pointer of the node to be inserted point to the next node of the node after which you want to insert the node  Make the next pointer of the node after which the node is to be inserted, point to the node to be inserted
  • 23. Traversal of a LL means to traverse each node of the list, and visiting each node exactly once. Algorithm: 1.Set Ptr to Start. 2.Repeat steps 3 and 4 until Ptr is not equal to Null. 3.Print the Info part of each node to which Ptr is pointing currently. 4.Advance the pointer Ptr so that it points to the next node. 5.End
  • 24. a b c d start Info NextPtr
  • 25. Logic using C Traverse() { Struct node *ptr; Ptr=start; While(ptr) { Print(“The current node %s”, ptritem-no); Ptr=ptrnext; } }
  • 26.  Searching involves finding the required element in the list  We can use various techniques of searching like linear search or binary search where binary search is more efficient in case of Arrays  But in case of linked list since random access is not available it would become complex to do binary search in it  We can perform simple linear search traversal
  • 27. Algorithm 1. Set Ptr to start 2. Input the item to be searched 3. While Ptr!=null do steps 4 and 5 4. Compare the item with the given value. If they are same ,exit from the loop and goto step 6, else 5. Set Ptr to next node 6. Report that the data found in the list .Otherwise it doesn’t exist .
  • 28. In linear search each node is traversed till the data in the node matches with the required value void search(int x) { node*temp=start; while(temp!=NULL) { if(temp->data==x) { Print “FOUND ”; break; } temp=temp->next; } }
  • 29. Deletion of a node is carried out in two steps viz, a) Logical deletion pointer shuffling in order to remove the links b) Physical deletion  release the memory occupied using free() function Here also we have three cases:-  Deleting the first node  Deleting the last node  Deleting the intermediate node
  • 30. Here we apply 3 steps:-  Making the start pointer point towards the 2nd node  Free the space associated with first node  Operating system collects the free space of the memory and use it with available free space. The process is given by  Temp=start;  Start=startnext;  Free(temp) threetwoone start
  • 31. Here we apply 2 steps:-  Traverse the list to find the last node.  Deleting the last node via delete keyword node3node2node1 start
  • 32.  Traverse the list to find the node to be deleted. Search is used for this purpose. Refer that as curr_ptr.  Then delete that node by setting the pointers as Prevnext=curr_ptrnext;  Then physical deletion is achieved by free(). node1 node2 node3 To be deleted
  • 33. The node in DLL may be deleted  At the beginning  At the end  At any desired position Steps to be followed 1. If the list is empty display underflow message 2. If a single node exists, set both the pointers as Null. Else if it is the first node, then delete it and update the pointers. 3. Else if, it is the last node, then delete it and update the right pointer. 4. Restore the deleted node to the free list
  • 34.  Generalized list A is a finite sequence of n>=0 elements.  A=(α0 ….. α n-1 ), here A  name of the list and α0 ….. α n-1 represents the elements. It is either atom or a list.  Name is given by capital letter and elements by small case. Ex: 1. D=() the null (or) empty list and its length is zero 2. A=(a(b,c)) a list of length 2 3. B=(A,A,())  a list of length 3, the third one is null. 4. C=(a,c)  a recursive list of length 2, c corresponds to the infinite list.
  • 35. Linked stack  In linked stack we can easily add a node at the top or delete a node from the top.  It is similar to push and pop the elements.  A stack can be accessed only through its top element,and a linked list can be accessed by using the pointer to its first element.
  • 36. 6 9 12 15 Top X Null Linked Stack
  • 37.  Linked list representations of queue are easy to handle.  We need two pointers namely Front and Rear.  Front represents the beginning of the queue and rear represents the end of the queue.  Q.Rear=null indicates the queue is empty.
  • 38. 6 9 12 15 Front X Rear Null Linked Queue
  • 39. 9 12 15 X Null Header Linked List Header Node The header for a LL is a pointer variable that locates the beginning of the list
  • 40.  HLL is a LL which always contains a special node called the header node.  Header node is at the beginning of the list.  Dummy nodes placed as the first node of a list which is used to simplify linked list processing.  It may or may not contain meaningful information.  It does not represents an item in the list.  The info portion of the such a header node might be unused.  It is used to keep the global information about the entire list.