 Hello everyone, I am Mrs. Meenakshi Shriganti from Walton Institute of Technology, Sholapur. Welcome to the video lecture on insertion of a node in a circular linked list. Learning outcome, at the end of this session, students will be able to explain the operation of insertion of a node in a circular linked list. Let's see the definition of linked list. A linked list is a linear data structure in which the elements are not stored at contiguous memory location. And it is a data structure consisting of a collection of nodes which together represents a sequence and are linked using pointers. Here is an example showing a linked list which consists of different nodes which are placed at different locations and these are linked together. Now the first node has been pointed by the pointer head and the last node has been terminated by a null. Definition of a node in a linked list. A node is an element in a linked list. It consists of two parts. The first part is called as the data part which contains the information. And the second part is called as the address part which is nothing but the pointer to the next node. And hence also known as the next part. Here is the node representation which consists of two parts. The first part is the data part which holds the information whereas the second part contains the address of the next node. And hence also called as next. Let's see the types of linked list. There are three types of linked list. The first is the single linked list which is having a single link to the next node and the last node has been terminated by a null. The second is called a circular linked list. In this the null part of the last node has been replaced with a link which is pointing to the first node. And the last is the doubly linked list. In this there are two links. One link is going to the next node and the other link is pointing to the previous node. Let's see the operations on linked list. There are different operations that can be performed on a linked list that are determine if the linked list is empty or not, insertion of an element in the list, deletion of an element from the list, search for a particular element in the list and display the elements in the list. In this video we are going to focus only on the operation of insertion of an element in the circular linked list. Let's see the insertion of a node in a circular linked list. Insertion of a node means adding a given element at the required location in the linked list. For this the process involves two steps. That is finding the correct location and insertion of the node. There are three ways for insertion of a node in a linked list. Those are insertion at the beginning of the list, insertion at the end of the list and insertion in between the nodes. Let's see the first one that is insertion of a node at the beginning of the linked list. For this there is no work to find the location. We need to check for the linked list is empty or not. If the linked list is empty then the new node will be the first node of the linked list. This can be illustrated by an example. In this example there is a linked list which is now empty. That is a linked list pointer, LL pointer is now pointing to empty. And our task is to add this new node to the linked list. For this the LL pointer is now assigned to the new node and the null part of this new node is now removed and it is made to point to the linked list pointer so that this becomes a circular linked list. If the linked list is not empty then the next part of the new node will point to the head node and the next part of the last node will point to the new. This can be illustrated by an example. Here is a circular linked list and our task is to add this new node at the beginning of the linked list. For this we need to traverse the linked list till we reach the last node and once we reach the last node the next part of the current node is now made to point to the new node and the next part of the new node is now point to the head node. After this has been done you can see that the new node has been added to the first node but the only thing is the LL pointer is now pointing to the second node. So once the new node becomes the first node we need to update the LL pointer to the new node. So for that LL pointer is now moved from the second node and it is now updated to point to the first node. So this is the updated circular linked list. Try to think and answer what is the algorithm for the insertion of a node at friend for a circular linked list. Pause the video for some time and note down the answer in your book. Algorithm for insertion of a node in friend for circular linked list. First we need to create a new node then fill in the data part of the new node check if the linked list is empty or not. If linked list is empty then set the LL to point to the new pointer and set the next of the LL pointer to point to LL. If the linked list is not empty then in that case set the next field of the last node to the new pointer and set the next field of the new node to point to LL pointer and update the current LL pointer to point to the new node. Let's see the second method that is insertion of a node at the end of the linked list. For this we need to find the end of the linked list for this we need to traverse the linked list until we reach the end of the list. Once we reach the end of the list then we need to add the new node and update the pointers. This can be illustrated by an example. Here is a circular linked list and our task is to add this new node at the last place of the circular linked list. For this we need to traverse the linked list till we reach the last node. Once we reach the last node then the next part of the current node is now assigned to the new node and the next part of the new node is now assigned to the head node. After this has been done then you can see that the new node has been added at the last place of the circular linked list. So this is a linked list after adding the new node at the last place. Try to think and answer what is the algorithm for insertion of a node at the end of the circular linked list. Pause the video for some time and note down the answer in your book. Algorithm for insertion of a node at the end of the circular linked list. First we need to create a new node then fill the data part of the new node fill the next part of the new node as null then recursively traverse the current linked list till we reach the last node. Once we reach the last node then point the next part of the last node to the new node and then point the next part of the new node to the head node. Let's see the last method of insertion that is insertion of a node after a given node in the linked list. This method is usually used when order is important. For that we need to go to the node that should follow the one that should be added through recursion or iteration. This can be illustrated by an example. Consider a circular linked list and we want to add this new node. Now this circular linked list is a sorted circular linked list so we need to add this new node in between 50 and 80. For this we need to traverse a node after which we need to add the new node. So once we reach the node after which the node has to be added then the next part of the new node has to be assigned to the next of the current node and the next of the current node should now be assigned to the new node. After insertion we can see that the new node is now added in between 50 and 80. So this is the updated circular linked list. Try to think an answer. What is the algorithm for insertion of a node after a given node in the circular linked list? Pause the video for some time and note down the answer in your book. Algorithm for insertion of a node after a given node in the circular linked list. First create a new node then fill the data part of the new node fill the next part of the new node as null recursively travels the current linked list via the current pointer till the node that should follow the one to add. After that is done then point the next part of the new node to the next node of the current node and point the next part of the current node to the new node. These are my references. Thank you.