SlideShare a Scribd company logo
1 of 40
Download to read offline
Linked List
Basics
Linked List –
It is a collection of similar data elements stored at discrete memory locations and
connected by a pointer (link). Hence size can grow or shrink at any point of time.
Data elements are called nodes
Types –
1. Linear linked list or singly linked list or one way list
2. Doubly linked list or two way list
3. Circular linked list
4. Header linked list
Linear Linked list
Each node has two fields – 1. Data (Information) 2. Pointer to next node
INFO INFO INFO INFO NULL
200 400 150 50
START
Representation of node –
struct Node{
int INFO;
struct Node *NEXT;
};
For start or head –
struct Node *START
Operations on linear linked list
1. Creating empty linked list
2. Traversing
3. Insertion
4. Deletion
5. Searching
6. Sorting
Creating a linked list
Algorithm Create_List()
1. Node * START
2. START= NULL
3. Return START
This function creates an empty linked list where START is a pointer pointing to created list.
//C program
struct Node* Create_List()
{ struct Node * START;
START= NULL;
return START;
}
struct Node{
int INFO;
struct Node *NEXT;
};
Traversing of linked list
Traversing the Linked List:
This function visits each node of linked list only once. Temp is a temporary pointer to
node. START is the pointer pointing to starting of list.
Algorithm Traverse_List(START)
1. Node * Temp
2. Temp = START
3. While (Temp != NULL)
4. Print Temp -> INFO
5. Temp = Temp -> NEXT
void Traverse_List(struct Node* START)
{
struct Node * Temp; //Temp pointer
Temp= START;
while (Temp!= NULL)
{
printf(" %d ", Temp -> INFO );
Temp = Temp ->NEXT;
}
}
Insertion
Three ways to insert a node into linked list –
1. Insert at beginning
2. Insert at the end (appending node)
3. Insert at specified location
Insertion at beginning of linked list
In this case, a new node is inserted before the current head node. Only one
next pointer needs to be modified (new node’s next pointer) and It can be
done in two steps:
Step 1. Update the next pointer of new node, to point to the current START or head
Step 2. Update START or head pointer to point to the new
node.
Insertion at beginning of linked list
Insert at the Beginning of the Linked List:
This function inserts a new node at the starting of linked list. New_Node is temporary
pointer to node to be inserted into list. START is the pointer pointing to starting of list and
info is the data of new node.
Algorithm InsertBeg_List(START, info)
1. Node * New_node
2. New_Node = Allocate memory allocate memory for new node
3. New_Node -> INFO =info put info in INFO field of new node
4. New_node -> NEXT = START
5. START = New_node
Insertion at End of linked list (Appending node)
Append node in a Linked List: Below function adds the node at the end of linked list.
New_Node is the node to be appended and Temp is temporary pointer. START is the
pointer pointing to starting of list and info is the information of node.
Algorithm Append_List(START, info)
1. Node* New_Node, *Temp
2. New_Node = Allocate memory allocate memory for new node
3. New_Node -> INFO =info put info in INFO field of new node
4. New_Node -> NEXT = NULL make it last node by keeping NULL in NEXT field
5. If (START == NULL)  if there is no node in list then make new node START
6. START = New_Node
7. Else
8. Temp = START
9. While (Temp -> NEXT != NULL)
10. Temp = Temp ->NEXT
11. Temp -> NEXT = New_Node
Insertion at given location of linked list
This algorithm adds at the specified location of linked list. Temp is temporary pointer and New_Node
is the pointer to the node to be inserted. START is the pointer pointing to starting of list and info is
the information of node. Loc is the numbered location where node is to be inserted. i is a loop
variable.
Algorithm InsertAt_Given_Loc(START, info, Loc)
1. Node * Temp=START, *New_node
2. New_node = Allocate memory
3. New_node -> INFO = info
4. If (Loc==1) // if Loc is 1 that means insert at first position
5. New_node -> NEXT =START
6. START = New_Node
7. Else if (Loc>=2 && START!=NULL)
8. For (i=1; i<=Loc-2; i++)
9. Temp = Temp -> NEXT
10. If (Temp == NULL) //if Loc is greater than number of nodes+1
11. Print “Loc is greater than number of nodes+1”
12. Return
13. New_node -> NEXT = Temp -> NEXT
14. Temp -> NEXT = New_node
15. Else
16. Print “Invalid loc”//loc<=0
Deletion
Three ways to delete a node from linked list –
1. Delete from beginning
2. Delete from the end
3. Delete node from specified location
NOTE: Deletion could be done on the basis of given data. Here, first find that node and
then delete it.
Deletion from the beginning of linked list
This algorithm deletes the node from the starting of linked list. Temp is temporary pointer.
START is the pointer pointing to starting of list.
Algorithm DeleteBeg_List(START)
1. Node* Temp = START
2. If START ==NULL
3. Print “Empty Linked List”
4. Return
5. START = START -> NEXT
6. Free Temp
Deletion from the End of linked list
This algorithm deletes the node from the end of the linked list. Temp and Temp1 are
temporary pointers. START is the pointer pointing to starting of list.
Algorithm DeleteEnd_List(START) –
1. Node * Temp, *Temp1
2. Temp1 = START
3. If START==NULL //checking Empty Linked list
4. Print “Empty Linked List”
5. Return
6. If(START->NEXT==NULL) // check single node list
7. START=NULL
8. Free Temp1
9. Return
10. While (Temp1 -> NEXT != NULL)
11. Temp =Temp1
12. Temp1 = Temp1 -> NEXT
13. Temp -> NEXT = NULL
14. Free Temp1
Deletion from specified location of linked list
This algorithm deletes the node from the specified location of linked list. Loc is the
numbered location from where node is to be deleted.
Algorithm DeleteFromLoc_List(START, Loc)
1. Node* Temp=START, *Temp1=START
2. If START==NULL || Loc<=0 //checking Empty Linked list or invalid loc
3. Print “Empty Linked List or invalid loc”
4. Return
5. If(Loc==1) // Delete first node
6. START= START->NEXT
7. Free Temp1
8. Else if (Loc>=2 && START->NEXT!=NULL )
9. For (i=1; i<=Loc-2; i++)
10. Temp = Temp -> NEXT
11. If (Temp->NEXT==NULL)
12. Print “Loc is greater than total number of nodes”
13. Return
14. Temp1 = Temp ->NEXT
15. Temp -> NEXT = Temp1 -> NEXT
16. Free Temp1
17. Else
18. Print “Loc is greater than total number of nodes”
Searching element in singly linked list
Only linear search – As there is no efficient way to find out the middle of linked list.
This algorithm searches the node in linked list. If element is found then return the location
number of node or return address of the node, otherwise return -1 or NULL.
Algorithm SearchUnsorted_List(START,info) –
1. Node *Temp
2. Initialize Loc = 0
3. Temp = START
4. If Temp==NULL //empty linked list
5. return
6. While (Temp != NULL)
7. Loc = Loc +1
8. If (Temp->INFO == info)
9. Return Loc // Return Temp
10. Temp = Temp -> NEXT
11. Return -1 // Return NULL
This algorithm searches the node in linked list. If element is found then return the location
number of node or return address of the node; otherwise return -1 or NULL.
Algorithm Search_Sorted_List(START,info) –
1. Node *Temp
2. Initialize Loc = 0
3. Temp = START
4. If Temp==NULL
5. Return
6. While (Temp != NULL)
7. Loc = Loc+1
8. If (Temp->INFO == info)
9. Return Loc // Return Temp
10. Else If (Temp->INFO > info)
11. Return -1 // Return NULL
12. Temp = Temp ->NEXT
13. Return -1 // Return NULL
Searching element in sorted singly linked list
Reverse the singly linked list
This algorithm reverses the linked list. Pnode, Cnode, and Nnode are temporary pointers.
START is the pointer pointing to starting node of the linked list.
Algorithm Reverse_List(START) –
1. Node *Cnode, *Pnode, *Nnode
2. If START==NULL // check Empty linked list
3. Return
4. Cnode =START
5. Nnode = Cnode ->NEXT
6. Cnode -> NEXT =NULL
7. While (Nnode != NULL)
8. Pnode = Cnode
9. Cnode = Nnode
10. Nnode = Nnode ->NEXT
11. Cnode -> NEXT = Pnode
12. START = Cnode
Arrays Vs. Linked List
Array Linked List
Elements stored at contiguous memory
locations.
Elements stored at discrete memory
locations.
Size of array is static and can not be
changed at later stage if need arise.
No fixed size, can grow and shrink very
efficiently
Array elements can be randomly accessed
using subscript variable.
e.g. a[0],a[1],a[3] etc.
Random access of any node is not possible
in linked list we have to traverse through
the linked list for accessing element. So O(n)
time is required for accessing particular
element .
Searching –
Unsorted list – Linear O(n)
Sorted list – Binary O(log2
n)
Searching – Only Linear O(n)
Insertion –
Shift all element one position right,
Less efficient than in linked list
Insertion –
Only some pointers need to be managed,
more efficient than in array
Deletion – Shift all element one position
left, Less efficient than in linked list
Deletion – Only some pointers need to be
managed, more efficient than in array
Doubly Linked list
Each node have three fields – 1. Information 2. Pointer to next node
3. Pointer to previous node
START
Representation of node –
struct Node{
struct Node *PREV;
int INFO;
struct Node *NEXT;
};
typedef struct Node Node;
For head –
Node *START, *END
N N
END
Creating a doubly linked list
This function creates an empty linked list and START is a pointer pointing to created list.
Algorithm Create_DList() –
1. Node *START, *END
2. START= NULL
3. END = NULL
Traversing of Doubly linked list
This function visits each node of linked list only once. Temp is a temporary pointer to node.
START and END are the pointers pointing to starting of list and end of list respectively.
Algorithm Traverse_Dlist_Forward(START) –
1. Node *Temp
2. Temp = START
3. While (Temp != NULL)
4. Print Temp -> INFO
5. Temp = Temp -> NEXT
Algorithm Traverse_Dlist_Backward(END) –
1. Node *Temp
2. Temp = END
3. While (Temp != NULL)
4. Print Temp -> INFO
5. Temp = Temp -> PREV
OR (from last to first)
Insertion
Three ways to insert a node into doubly linked list –
1. Insert at beginning
2. Insert at the end (also known as appending)
3. Insert at specified location
Insertion at beginning of Doubly linked list
This function adds the node at the starting of linked list. New_node is temporary pointer
to node to be inserted into list. START and END are the pointers pointing to first and last
nodes in a doubly linked list and info is the information of node.
Algorithm InsertBeg_DList(START,END, info) –
1. Node *New_node
2. New_node = Allocate memory
3. New_node -> INFO =info
4. New_node -> NEXT = START
5. New_node ->PREV = NULL
6. If START==NULL // linked list is empty
7. START = New_node
8. END= New_node
9. else
10. START -> PREV= New_node
11. START = New_node
Insertion at End(Appending) of Doubly linked list
This function add the node at the end of linked list. New_node is temporary pointers.
START and END are the pointers pointing to starting of list and end of list respectively. info
is the information of node.
.
Algorithm InsertEnd_DList(START ,END, info) –
1. Node *New_node
2. New_node = Allocate memory
3. New_node -> INFO =info
4. New_node -> NEXT = NULL
5. If (START == NULL OR END == NULL)  if there is no node in list
6. New_node -> PREV = NULL
7. START = New_node
8. END = New_node
9. Else
10. New_node -> PREV = END
11. END -> NEXT = New_node
12. END = New_node
Insertion at specified location of doubly linked list
Algorithm InsertAt_Loc_DList(START,END, info, Loc) –
1. Node *Temp=START, *New_node
2. New_node = Allocate memory
3. New_node -> INFO = info
4. If Loc==1
5. New_node -> NEXT = START
6. New_node ->PREV = NULL
7. If START==NULL // linked list is empty
8. END=New_node
9. Else START -> PREV= New_node
10. START = New_node
11. Else if (Loc>=2 && Temp!=NULL)
12. For (i=1; i<=Loc-2; i=i+1)
13. Temp = Temp -> NEXT
14. If (Temp == NULL) //if Loc is greater than number of nodes+1
15. Print “Loc is greater than number of nodes+1”
16. Return
17. New_node -> NEXT = Temp -> NEXT
18. New_node -> PREV = Temp
19. If Temp -> NEXT!=NULL
20. (Temp -> NEXT) -> PREV = New_node // only when LOC is not a last node
21. Temp -> NEXT = New_node
22. Else Print “Invalid loc” //Loc<=0
Deletion
Three ways to Delete a node from linked list –
1. Delete from beginning
2. Delete from the end
3. Delete from specified location
NOTE: Deletion could be done on the basis of information available at any
node. Here, first find that node and then delete it.
Deletion at beginning of linked list
This function delete the node from the starting of linked list. Temp is temporary pointer.
START and END are the pointers pointing to starting of list and end of list.
Algorithm DeleteBeg_DList(START,END) –
1. Node *Temp = START
2. If Temp ==NULL // Empty list
3. Exit
4. If (START == END) // Single Node
5. START = END =NULL
6. ELSE
7. (Temp ->NEXT) -> PREV =NULL
8. START = START -> NEXT
9. Free Temp
Deletion at End of linked list
This function delete the node at the end of linked list. Temp and Temp1 are temporary
pointers. END is the pointer pointing to end of list.
Algorithm DeleteEnd_List(START,END) –
1. Node *Temp, *Temp1
2. Temp = END
3. If Temp==NULL
4. return
5. If (START == END) // Single Node
6. START = END =NULL
7. Else
8. Temp1 = Temp -> PREV
9. Temp1 -> NEXT = NULL
10. END = Temp1
11. Free Temp
Deletion from specified location of linked list
Algorithm DeleteFromLoc_DList(START, END, Loc) –
1. Node *Temp=START, *Temp1=START
2. If START==NULL || Loc<=0//checking Empty Linked list or invalid Loc
3. Print “Empty Linked List or Loc is invalid ”
4. Return
5. If(Loc==1) // Delete first node
6. If (START == END) // Single Node
7. START = END =NULL
8. ELSE
9. (Temp ->NEXT) -> PREV = NULL
10. START = START -> NEXT
11. Else if (Loc>=2 && Temp->NEXT!=NULL)
12. For (i=1; i<=Loc-2; i++)
13. Temp = Temp -> NEXT
14. If (Temp->NEXT==NULL)
15. Print “Loc is greater than total number of nodes”
16. Return
17. Temp1 = Temp ->NEXT
18. Temp -> NEXT = Temp1 -> NEXT
19. If Temp1->NEXT!=NULL
20. (Temp1->NEXT) ->PREV = Temp // only when LOC is not a last node
21. Else END=Temp
22. Else
23. Print “Loc is greater than total number of nodes”
24. Return
25. Free Temp1
Singly Vs. Doubly Linked List
Singly Linked List Doubly Linked List
Node has two fields. Node has three fields.
Reverse traversing is not possible. Reverse traversing is possible.
Insertion at the end of linked list takes
O(n) time.
Insertion at the end of linked list take
constant time
Deletion at the end of linked list take O(n)
time and deletion before specified location
is not possible.
Deletion at the end of linked list take
constant time and deletion before
specified location is also possible.
Exercises
1. Write an algorithm for searching in doubly linked list.
2. Write an algorithm to sorting a singly linked list.
3. Why reverse algorithm is not needed in doubly linked list. Justify your answer comparing
with singly linked list.
4. Write an algorithm to delete the entire singly linked list or doubly linked list.
Circular Linked list
It could be singly or doubly linked list.
For singly circular linked list
Each node have two fields – 1. Information 2. Pointer to next node
data data data data
200 400 150 50
END
Representation of node –
struct Node{
int INFO;
struct Node *NEXT;
};
Supported operations
All the operations which can be performed on singly or doubly linked list can be
extended to circular linked list by maintaining last node next pointer to first node.
1. Creating empty linked list
2. Appending nodes to linked list
3. Traversing
4. Insertion
5. Deletion
6. Searching
7. Sorting
How do we know end of list ?
Compare next pointer field with address of first node or head
Circular Linked list
Advantages:
Any node can be a starting point. We can traverse the whole list by starting from any
point. We just need to stop when the first visited node is visited again.
It saves time when we have to go to the first node from the last node. It can be done in
single step because there is no need to traverse in between the nodes. But in doubly
linked list, we will have to go through in between nodes.
Disadvantages:
1. It is not easy to reverse the circular linked list. If proper care is not taken, then the
problem of infinite loop can occur.
2. If we want to go back to the previous node, then we can not do it in single step. Entire
circle to be covered.
Circular Linked list
For circular linked list should we maintain START or END pointer ?
For insertion of node in the beginning we need to traverse the whole list.
Also, for insertion at the end, the whole list has to be traversed.
If instead of start pointer we take a pointer to the last node then in both the cases
there won’t be any need to traverse the whole list.
So insertion in the beginning or at the end takes constant time irrespective of the
length of the list.
Circular Linked list(Insert at beginning)
Algorithm InsertBeg_List(END, info)
1. Node * New_node
2. New_Node = Allocate memory allocate memory for new node
3. New_Node -> INFO =info put info in INFO field of new node
4. If END==NULL
5. New_node -> NEXT = New_node
6. END=New_node
7. Else
8. New_node -> NEXT = END->NEXT
9. END->NEXT = New_node
Circular Linked list(Insert at the end)
Algorithm InsertAt_Last_List(END, info)
1. Node *New_node
2. New_Node = Allocate memory allocate memory for new node
3. New_Node -> INFO =info put info in INFO field of new node
4. If END ==NULL
5. New_node -> NEXT = New_node
6. END =New_node
7. Else
8. New_node -> NEXT = END ->NEXT
9. END ->NEXT = New_node
10. END =New_node;
Header Linked list
A Header linked list is one more variant of linked list. In Header linked list, we have a special
node present at the beginning of the linked list.
Header node keeps information about list like number of nodes, sorted or not sorted etc.
Application of Linked list
To implement scheduling algorithms in Operating Systems
To represent sparse matrices
To implement other data structures like stack, queue, tree etc.
To manipulate polynomials
In image viewer – Previous and next images are linked, hence can be accessed
by next and previous button. Open a folder that has images. Use Microsoft
Image Viewer to view the images. In the User Interface, '->' button is
your node->next; The '<-' button is your node->prev.
For other application visit following link:
https://www.geeksforgeeks.org/applications-of-linked-list-data-structure/

More Related Content

Similar to linkrd_list.pdf

Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptxnikhilcse1
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxMeghaKulkarni27
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssbeshahashenafe20
 
Circular linked list
Circular linked list Circular linked list
Circular linked list sajinis3
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptxmsohail37
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptssuser9dd05f
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of listsmuskans14
 

Similar to linkrd_list.pdf (20)

Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Linked List
Linked ListLinked List
Linked List
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Link list assi
Link list assiLink list assi
Link list assi
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 
Link list 2
Link list 2Link list 2
Link list 2
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
single linked list
single linked listsingle linked list
single linked list
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
 

Recently uploaded

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 

Recently uploaded (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

linkrd_list.pdf

  • 2. Basics Linked List – It is a collection of similar data elements stored at discrete memory locations and connected by a pointer (link). Hence size can grow or shrink at any point of time. Data elements are called nodes Types – 1. Linear linked list or singly linked list or one way list 2. Doubly linked list or two way list 3. Circular linked list 4. Header linked list
  • 3. Linear Linked list Each node has two fields – 1. Data (Information) 2. Pointer to next node INFO INFO INFO INFO NULL 200 400 150 50 START Representation of node – struct Node{ int INFO; struct Node *NEXT; }; For start or head – struct Node *START
  • 4. Operations on linear linked list 1. Creating empty linked list 2. Traversing 3. Insertion 4. Deletion 5. Searching 6. Sorting
  • 5. Creating a linked list Algorithm Create_List() 1. Node * START 2. START= NULL 3. Return START This function creates an empty linked list where START is a pointer pointing to created list. //C program struct Node* Create_List() { struct Node * START; START= NULL; return START; } struct Node{ int INFO; struct Node *NEXT; };
  • 6. Traversing of linked list Traversing the Linked List: This function visits each node of linked list only once. Temp is a temporary pointer to node. START is the pointer pointing to starting of list. Algorithm Traverse_List(START) 1. Node * Temp 2. Temp = START 3. While (Temp != NULL) 4. Print Temp -> INFO 5. Temp = Temp -> NEXT void Traverse_List(struct Node* START) { struct Node * Temp; //Temp pointer Temp= START; while (Temp!= NULL) { printf(" %d ", Temp -> INFO ); Temp = Temp ->NEXT; } }
  • 7. Insertion Three ways to insert a node into linked list – 1. Insert at beginning 2. Insert at the end (appending node) 3. Insert at specified location
  • 8. Insertion at beginning of linked list In this case, a new node is inserted before the current head node. Only one next pointer needs to be modified (new node’s next pointer) and It can be done in two steps: Step 1. Update the next pointer of new node, to point to the current START or head Step 2. Update START or head pointer to point to the new node.
  • 9. Insertion at beginning of linked list Insert at the Beginning of the Linked List: This function inserts a new node at the starting of linked list. New_Node is temporary pointer to node to be inserted into list. START is the pointer pointing to starting of list and info is the data of new node. Algorithm InsertBeg_List(START, info) 1. Node * New_node 2. New_Node = Allocate memory allocate memory for new node 3. New_Node -> INFO =info put info in INFO field of new node 4. New_node -> NEXT = START 5. START = New_node
  • 10. Insertion at End of linked list (Appending node) Append node in a Linked List: Below function adds the node at the end of linked list. New_Node is the node to be appended and Temp is temporary pointer. START is the pointer pointing to starting of list and info is the information of node. Algorithm Append_List(START, info) 1. Node* New_Node, *Temp 2. New_Node = Allocate memory allocate memory for new node 3. New_Node -> INFO =info put info in INFO field of new node 4. New_Node -> NEXT = NULL make it last node by keeping NULL in NEXT field 5. If (START == NULL) if there is no node in list then make new node START 6. START = New_Node 7. Else 8. Temp = START 9. While (Temp -> NEXT != NULL) 10. Temp = Temp ->NEXT 11. Temp -> NEXT = New_Node
  • 11. Insertion at given location of linked list This algorithm adds at the specified location of linked list. Temp is temporary pointer and New_Node is the pointer to the node to be inserted. START is the pointer pointing to starting of list and info is the information of node. Loc is the numbered location where node is to be inserted. i is a loop variable. Algorithm InsertAt_Given_Loc(START, info, Loc) 1. Node * Temp=START, *New_node 2. New_node = Allocate memory 3. New_node -> INFO = info 4. If (Loc==1) // if Loc is 1 that means insert at first position 5. New_node -> NEXT =START 6. START = New_Node 7. Else if (Loc>=2 && START!=NULL) 8. For (i=1; i<=Loc-2; i++) 9. Temp = Temp -> NEXT 10. If (Temp == NULL) //if Loc is greater than number of nodes+1 11. Print “Loc is greater than number of nodes+1” 12. Return 13. New_node -> NEXT = Temp -> NEXT 14. Temp -> NEXT = New_node 15. Else 16. Print “Invalid loc”//loc<=0
  • 12. Deletion Three ways to delete a node from linked list – 1. Delete from beginning 2. Delete from the end 3. Delete node from specified location NOTE: Deletion could be done on the basis of given data. Here, first find that node and then delete it.
  • 13. Deletion from the beginning of linked list This algorithm deletes the node from the starting of linked list. Temp is temporary pointer. START is the pointer pointing to starting of list. Algorithm DeleteBeg_List(START) 1. Node* Temp = START 2. If START ==NULL 3. Print “Empty Linked List” 4. Return 5. START = START -> NEXT 6. Free Temp
  • 14. Deletion from the End of linked list This algorithm deletes the node from the end of the linked list. Temp and Temp1 are temporary pointers. START is the pointer pointing to starting of list. Algorithm DeleteEnd_List(START) – 1. Node * Temp, *Temp1 2. Temp1 = START 3. If START==NULL //checking Empty Linked list 4. Print “Empty Linked List” 5. Return 6. If(START->NEXT==NULL) // check single node list 7. START=NULL 8. Free Temp1 9. Return 10. While (Temp1 -> NEXT != NULL) 11. Temp =Temp1 12. Temp1 = Temp1 -> NEXT 13. Temp -> NEXT = NULL 14. Free Temp1
  • 15. Deletion from specified location of linked list This algorithm deletes the node from the specified location of linked list. Loc is the numbered location from where node is to be deleted. Algorithm DeleteFromLoc_List(START, Loc) 1. Node* Temp=START, *Temp1=START 2. If START==NULL || Loc<=0 //checking Empty Linked list or invalid loc 3. Print “Empty Linked List or invalid loc” 4. Return 5. If(Loc==1) // Delete first node 6. START= START->NEXT 7. Free Temp1 8. Else if (Loc>=2 && START->NEXT!=NULL ) 9. For (i=1; i<=Loc-2; i++) 10. Temp = Temp -> NEXT 11. If (Temp->NEXT==NULL) 12. Print “Loc is greater than total number of nodes” 13. Return 14. Temp1 = Temp ->NEXT 15. Temp -> NEXT = Temp1 -> NEXT 16. Free Temp1 17. Else 18. Print “Loc is greater than total number of nodes”
  • 16. Searching element in singly linked list Only linear search – As there is no efficient way to find out the middle of linked list. This algorithm searches the node in linked list. If element is found then return the location number of node or return address of the node, otherwise return -1 or NULL. Algorithm SearchUnsorted_List(START,info) – 1. Node *Temp 2. Initialize Loc = 0 3. Temp = START 4. If Temp==NULL //empty linked list 5. return 6. While (Temp != NULL) 7. Loc = Loc +1 8. If (Temp->INFO == info) 9. Return Loc // Return Temp 10. Temp = Temp -> NEXT 11. Return -1 // Return NULL
  • 17. This algorithm searches the node in linked list. If element is found then return the location number of node or return address of the node; otherwise return -1 or NULL. Algorithm Search_Sorted_List(START,info) – 1. Node *Temp 2. Initialize Loc = 0 3. Temp = START 4. If Temp==NULL 5. Return 6. While (Temp != NULL) 7. Loc = Loc+1 8. If (Temp->INFO == info) 9. Return Loc // Return Temp 10. Else If (Temp->INFO > info) 11. Return -1 // Return NULL 12. Temp = Temp ->NEXT 13. Return -1 // Return NULL Searching element in sorted singly linked list
  • 18. Reverse the singly linked list This algorithm reverses the linked list. Pnode, Cnode, and Nnode are temporary pointers. START is the pointer pointing to starting node of the linked list. Algorithm Reverse_List(START) – 1. Node *Cnode, *Pnode, *Nnode 2. If START==NULL // check Empty linked list 3. Return 4. Cnode =START 5. Nnode = Cnode ->NEXT 6. Cnode -> NEXT =NULL 7. While (Nnode != NULL) 8. Pnode = Cnode 9. Cnode = Nnode 10. Nnode = Nnode ->NEXT 11. Cnode -> NEXT = Pnode 12. START = Cnode
  • 19. Arrays Vs. Linked List Array Linked List Elements stored at contiguous memory locations. Elements stored at discrete memory locations. Size of array is static and can not be changed at later stage if need arise. No fixed size, can grow and shrink very efficiently Array elements can be randomly accessed using subscript variable. e.g. a[0],a[1],a[3] etc. Random access of any node is not possible in linked list we have to traverse through the linked list for accessing element. So O(n) time is required for accessing particular element . Searching – Unsorted list – Linear O(n) Sorted list – Binary O(log2 n) Searching – Only Linear O(n) Insertion – Shift all element one position right, Less efficient than in linked list Insertion – Only some pointers need to be managed, more efficient than in array Deletion – Shift all element one position left, Less efficient than in linked list Deletion – Only some pointers need to be managed, more efficient than in array
  • 20. Doubly Linked list Each node have three fields – 1. Information 2. Pointer to next node 3. Pointer to previous node START Representation of node – struct Node{ struct Node *PREV; int INFO; struct Node *NEXT; }; typedef struct Node Node; For head – Node *START, *END N N END
  • 21. Creating a doubly linked list This function creates an empty linked list and START is a pointer pointing to created list. Algorithm Create_DList() – 1. Node *START, *END 2. START= NULL 3. END = NULL
  • 22. Traversing of Doubly linked list This function visits each node of linked list only once. Temp is a temporary pointer to node. START and END are the pointers pointing to starting of list and end of list respectively. Algorithm Traverse_Dlist_Forward(START) – 1. Node *Temp 2. Temp = START 3. While (Temp != NULL) 4. Print Temp -> INFO 5. Temp = Temp -> NEXT Algorithm Traverse_Dlist_Backward(END) – 1. Node *Temp 2. Temp = END 3. While (Temp != NULL) 4. Print Temp -> INFO 5. Temp = Temp -> PREV OR (from last to first)
  • 23. Insertion Three ways to insert a node into doubly linked list – 1. Insert at beginning 2. Insert at the end (also known as appending) 3. Insert at specified location
  • 24. Insertion at beginning of Doubly linked list This function adds the node at the starting of linked list. New_node is temporary pointer to node to be inserted into list. START and END are the pointers pointing to first and last nodes in a doubly linked list and info is the information of node. Algorithm InsertBeg_DList(START,END, info) – 1. Node *New_node 2. New_node = Allocate memory 3. New_node -> INFO =info 4. New_node -> NEXT = START 5. New_node ->PREV = NULL 6. If START==NULL // linked list is empty 7. START = New_node 8. END= New_node 9. else 10. START -> PREV= New_node 11. START = New_node
  • 25. Insertion at End(Appending) of Doubly linked list This function add the node at the end of linked list. New_node is temporary pointers. START and END are the pointers pointing to starting of list and end of list respectively. info is the information of node. . Algorithm InsertEnd_DList(START ,END, info) – 1. Node *New_node 2. New_node = Allocate memory 3. New_node -> INFO =info 4. New_node -> NEXT = NULL 5. If (START == NULL OR END == NULL) if there is no node in list 6. New_node -> PREV = NULL 7. START = New_node 8. END = New_node 9. Else 10. New_node -> PREV = END 11. END -> NEXT = New_node 12. END = New_node
  • 26. Insertion at specified location of doubly linked list Algorithm InsertAt_Loc_DList(START,END, info, Loc) – 1. Node *Temp=START, *New_node 2. New_node = Allocate memory 3. New_node -> INFO = info 4. If Loc==1 5. New_node -> NEXT = START 6. New_node ->PREV = NULL 7. If START==NULL // linked list is empty 8. END=New_node 9. Else START -> PREV= New_node 10. START = New_node 11. Else if (Loc>=2 && Temp!=NULL) 12. For (i=1; i<=Loc-2; i=i+1) 13. Temp = Temp -> NEXT 14. If (Temp == NULL) //if Loc is greater than number of nodes+1 15. Print “Loc is greater than number of nodes+1” 16. Return 17. New_node -> NEXT = Temp -> NEXT 18. New_node -> PREV = Temp 19. If Temp -> NEXT!=NULL 20. (Temp -> NEXT) -> PREV = New_node // only when LOC is not a last node 21. Temp -> NEXT = New_node 22. Else Print “Invalid loc” //Loc<=0
  • 27. Deletion Three ways to Delete a node from linked list – 1. Delete from beginning 2. Delete from the end 3. Delete from specified location NOTE: Deletion could be done on the basis of information available at any node. Here, first find that node and then delete it.
  • 28. Deletion at beginning of linked list This function delete the node from the starting of linked list. Temp is temporary pointer. START and END are the pointers pointing to starting of list and end of list. Algorithm DeleteBeg_DList(START,END) – 1. Node *Temp = START 2. If Temp ==NULL // Empty list 3. Exit 4. If (START == END) // Single Node 5. START = END =NULL 6. ELSE 7. (Temp ->NEXT) -> PREV =NULL 8. START = START -> NEXT 9. Free Temp
  • 29. Deletion at End of linked list This function delete the node at the end of linked list. Temp and Temp1 are temporary pointers. END is the pointer pointing to end of list. Algorithm DeleteEnd_List(START,END) – 1. Node *Temp, *Temp1 2. Temp = END 3. If Temp==NULL 4. return 5. If (START == END) // Single Node 6. START = END =NULL 7. Else 8. Temp1 = Temp -> PREV 9. Temp1 -> NEXT = NULL 10. END = Temp1 11. Free Temp
  • 30. Deletion from specified location of linked list Algorithm DeleteFromLoc_DList(START, END, Loc) – 1. Node *Temp=START, *Temp1=START 2. If START==NULL || Loc<=0//checking Empty Linked list or invalid Loc 3. Print “Empty Linked List or Loc is invalid ” 4. Return 5. If(Loc==1) // Delete first node 6. If (START == END) // Single Node 7. START = END =NULL 8. ELSE 9. (Temp ->NEXT) -> PREV = NULL 10. START = START -> NEXT 11. Else if (Loc>=2 && Temp->NEXT!=NULL) 12. For (i=1; i<=Loc-2; i++) 13. Temp = Temp -> NEXT 14. If (Temp->NEXT==NULL) 15. Print “Loc is greater than total number of nodes” 16. Return 17. Temp1 = Temp ->NEXT 18. Temp -> NEXT = Temp1 -> NEXT 19. If Temp1->NEXT!=NULL 20. (Temp1->NEXT) ->PREV = Temp // only when LOC is not a last node 21. Else END=Temp 22. Else 23. Print “Loc is greater than total number of nodes” 24. Return 25. Free Temp1
  • 31. Singly Vs. Doubly Linked List Singly Linked List Doubly Linked List Node has two fields. Node has three fields. Reverse traversing is not possible. Reverse traversing is possible. Insertion at the end of linked list takes O(n) time. Insertion at the end of linked list take constant time Deletion at the end of linked list take O(n) time and deletion before specified location is not possible. Deletion at the end of linked list take constant time and deletion before specified location is also possible.
  • 32. Exercises 1. Write an algorithm for searching in doubly linked list. 2. Write an algorithm to sorting a singly linked list. 3. Why reverse algorithm is not needed in doubly linked list. Justify your answer comparing with singly linked list. 4. Write an algorithm to delete the entire singly linked list or doubly linked list.
  • 33. Circular Linked list It could be singly or doubly linked list. For singly circular linked list Each node have two fields – 1. Information 2. Pointer to next node data data data data 200 400 150 50 END Representation of node – struct Node{ int INFO; struct Node *NEXT; };
  • 34. Supported operations All the operations which can be performed on singly or doubly linked list can be extended to circular linked list by maintaining last node next pointer to first node. 1. Creating empty linked list 2. Appending nodes to linked list 3. Traversing 4. Insertion 5. Deletion 6. Searching 7. Sorting How do we know end of list ? Compare next pointer field with address of first node or head
  • 35. Circular Linked list Advantages: Any node can be a starting point. We can traverse the whole list by starting from any point. We just need to stop when the first visited node is visited again. It saves time when we have to go to the first node from the last node. It can be done in single step because there is no need to traverse in between the nodes. But in doubly linked list, we will have to go through in between nodes. Disadvantages: 1. It is not easy to reverse the circular linked list. If proper care is not taken, then the problem of infinite loop can occur. 2. If we want to go back to the previous node, then we can not do it in single step. Entire circle to be covered.
  • 36. Circular Linked list For circular linked list should we maintain START or END pointer ? For insertion of node in the beginning we need to traverse the whole list. Also, for insertion at the end, the whole list has to be traversed. If instead of start pointer we take a pointer to the last node then in both the cases there won’t be any need to traverse the whole list. So insertion in the beginning or at the end takes constant time irrespective of the length of the list.
  • 37. Circular Linked list(Insert at beginning) Algorithm InsertBeg_List(END, info) 1. Node * New_node 2. New_Node = Allocate memory allocate memory for new node 3. New_Node -> INFO =info put info in INFO field of new node 4. If END==NULL 5. New_node -> NEXT = New_node 6. END=New_node 7. Else 8. New_node -> NEXT = END->NEXT 9. END->NEXT = New_node
  • 38. Circular Linked list(Insert at the end) Algorithm InsertAt_Last_List(END, info) 1. Node *New_node 2. New_Node = Allocate memory allocate memory for new node 3. New_Node -> INFO =info put info in INFO field of new node 4. If END ==NULL 5. New_node -> NEXT = New_node 6. END =New_node 7. Else 8. New_node -> NEXT = END ->NEXT 9. END ->NEXT = New_node 10. END =New_node;
  • 39. Header Linked list A Header linked list is one more variant of linked list. In Header linked list, we have a special node present at the beginning of the linked list. Header node keeps information about list like number of nodes, sorted or not sorted etc.
  • 40. Application of Linked list To implement scheduling algorithms in Operating Systems To represent sparse matrices To implement other data structures like stack, queue, tree etc. To manipulate polynomials In image viewer – Previous and next images are linked, hence can be accessed by next and previous button. Open a folder that has images. Use Microsoft Image Viewer to view the images. In the User Interface, '->' button is your node->next; The '<-' button is your node->prev. For other application visit following link: https://www.geeksforgeeks.org/applications-of-linked-list-data-structure/