 Hello everyone, I am Mrs. Meenakshi Shrigandhi from Vultured Institute of Technology Shalapur. Welcome to the video lecture on Deletion of a node from a circular linked list. Learning outcome. At the end of this session, students will be able to explain the operation of deletion of a node from a circular linked list. Definition of linked list. A linked list is a linear data structure in which the elements are not stored at contiguous memory locations. It is a data structure consisting of a collection of nodes which together represents a sequence and are linked using pointer. It is an example which shows nodes at different memory locations which are linked by using pointers. So, it represents a linked list. 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 a data part which contains the information and the second part is called as the address part which is a pointer to the next node and hence also known as next part. Here it shows the node representation which consists of two parts. The first part is the data part which holds the information whereas the second part is the address of the next node. Let us see the types of linked list. There are three types of linked list that is a single linked list. Here it shows a single linked list which consists of a single link to the next node. A circular linked list in which an null is replaced by a link to the first node. A double linked list which consists of two links one link going to the next node and the other link going to the previous node. Let us see the operations on linked list. There are different operations that can be performed on a linked list. Those are to determine if the list is empty, 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 on deletion of an element from the list in a circular linked list. Let us see the deletion of a node from a circular linked list. Deletion of a node means removing the element of interest from the linked list. For that this process involves two steps. The first is to find the element to be deleted and second is deletion of the node with pointer adjustment. Here deletion of the node is done by using pointer adjustment. This type of deletion is called as logical deletion. There are three ways for deletion of a node from the linked list. That is the first node of the linked list, the last node of the linked list and at any given position in the linked list. Let us see the first way of deletion, that is deletion of first node from the linked list. For this there is no work to find the location, only we need to check if the list is empty or not. If the list is empty then we need to display the message as no need to delete from the linked list. Here it shows an example where a linked list pointer LL represents the pointer to the linked list. Initially it is empty. Now when LL pointer is pointing to empty it in that case we need to print the message as no need to delete from the linked list. But if the linked list is not empty then simply we need to make the external pointer list equal to the next field of the first node in the list. This can be illustrated by an example. Here is the circular linked list and we want to delete the first node from the linked list. For this first we are assigning a temporary pointer P. Now if you want to delete the first node from the circular linked list only we need to assign list to the next of list. That means that list pointer should be moved from the first node and it should be assigned to the second node. After that has been done we need to traverse till the last node of the linked list and the next part of the last node should now assign to list. If this is done then the first node of the linked list gets deleted from the circular linked list. So after deletion the deleted node is pointed by the pointer P and this is the linked list after deletion of the node with value 40. Trying to think and answer what is the algorithm for deletion of first node from a circular linked list. Pause the video for some time and note down the answer in your book. Algorithm for deletion of first node from the circular linked list. Input from the user the node to be deleted say X. Check if the list is empty or not. If empty then no node to be deleted should be printed. If not empty then we need to set the P pointer to the first node that is node to be deleted and we need to make the external pointer list equal to the next field of the first node and after that update the next part of the last node to the pointer list. Let's see the second way that is deletion of a last node from the circular linked list. In this we need to traverse till last node with two pointers to keep track of trail node and the current node. After that we need to assign the next of trail node to next of current node that is node to be deleted. This can be illustrated by an example. This is a circular linked list and here our task is to delete the last node from the circular linked list that is the node with value 110 is to be deleted. For that we need to traverse till the last node with two pointers trail is pointing to the previous node and current is a pointer pointing to the node to be deleted. After that is done only we need to assign trail of next to current of next. So the node where current is pointing with value 110 gets deleted. So after deletion the deleted node is pointed by current. This is the updated linked list after deletion of a node with 110. Try to think and answer what is the algorithm for deletion of last node from the circular linked list. Pause the video for some time and note down the answer in your book. Algorithm for deletion of last node from the circular linked list. Input from the user the node to be deleted say x initialize the pointers current and trail travels the linked list till current reaches the last node with value x of the linked list. Assign next of trail to next of current to delete the node pointed by the current. Let's see a case where we have a single node in the circular linked list and we want to delete it. So for that check if the linked list contains a single node. If it contains a single node then assign the list pointer to null. This can be illustrated by an example. Consider a circular linked list where it contains a single node and here our task is to delete the node. If we delete the node we know that after deletion the list pointer will now point to null. So the current now will point to the node to be deleted and list will now point to null. So when the circular linked list consists of a single node then to delete that node only we need to assign the list pointer to null. This automatically deletes the node. Try to think and answer what is the algorithm for deletion of a single node from a circular linked list. Pause the video for some time and note down the answer in your book. So for deletion of a single node from the circular linked list, input from the user the node to be deleted called say X check if the linked list contains single node or not. If yes assign the null to the list pointer. Let's see deletion of a node which is placed in the middle of the circular linked list. For that first we need to find the node containing value X. For that we need to have two pointers to keep track of the current node and the previous node. And after that we need to traverse the list till we reach the node to be deleted. Here is an example which shows a circular linked list and our task is to delete a node with value 80. For that we are assigning two pointers called as trail which is initially assigned to null and current which is pointing to the first node. Now here the value of X is compared with the node where current is pointing. As you can see that the node value is not equal to X then trail is now moved to the current place and current is moved to the next node. Now this comparison is carried out till trail is pointing to 70 and current will point to 80. After that we can see that the comparison with value X and the node where current is pointing is equal. Now when this is reached then we can say that the node to be deleted is found. In the next step we want to delete this node so we need to modify the pointers to delete the node. For that the pointers have to be adjusted for deletion of the node from the existing linked list. From the previous example we have seen that we want to delete the node with value 80 where current is pointing. To delete the node with value 80 where current is pointing only we need to adjust trail of next to current of next. Once it is done then the node with value 80 where current is pointing gets deleted. So after deletion you can see that the node to be deleted is pointed by current and this is the updated circular linked list after deletion of the node with value 80. Now in some of the cases the node to be deleted is not present in the circular linked list. To understand about that we will be considering an example. First current of the next is equal to list after traversing the linked list and x is not equal to the data of the node where current is pointing. This can be illustrated by an example. This is a circular linked list and we want to delete a node with value 110. As discussed in the previous example we need to have two pointers trail and current. Now every time the node with where current is pointing that node is compared with value x. Whenever the comparison is not equal trail and current both are moved to the next node. So at one point trail is pointing to 80 and current is pointing to the last node of the linked list. But you can see that here the comparison of x and current of data is not equal. So when current of data is not equal to the value of x then we can say that the node to be deleted is not found. Try to think and answer what is the algorithm for deletion of a node which is placed in the middle of the linked list. Pause the video for some time and note down the answer in your book. Algorithm for deletion of a node which is placed in the middle of the circular linked list. Input from the user the node to be deleted say x. Initialize the pointers current and trail. Traverse the linked list till current of data is not equal to x and current of next not equal to list. If step 3 is true advanced trail and current if x is equal to data where current is pointing then we need to delete the node where current is pointing by assigning the next part of trail to next part of the current. Else we can print that the node to be deleted is not found. These are my references. Thank you.