 Hello everyone, my name is Nikhil Gadjum working as assistant professor in department of computer science and engineering in Balchand Institute of Technology, Solapur. In today's video, we will see searching and updating an element in singly circular linked list. Learning outcomes at the end of this session, student will be able to write a C program for searching an element or a node in singly circular linked list and student will be able to write a C program for updating a node in singly circular linked list. Now, this is a singly circular linked list, diagrammatically representation. Next one, we will see an algorithm for searching a node from singly circular linked list. So step one, traverse the singly circular linked list from first node to last node using a temporary pointer. Again, how to find out the first node using a start pointer, start or head pointer. So these are global pointer, start pointer or head pointer. So there is only one global pointer we are using in singly circular linked list that is head or a start which always points to the first node. Now how to find out whether a node is last node or not? A node whose next pointer holds the address of first node or start. So this represents a last node. So using temporary pointer you have to traverse from first to last, don't change the value of start. Start will always holds the address of first node. Step 2, compare element which is to be searched with a data part of each and every node. So while traversing from first node to last node, you are comparing an element to be searched with a data part of a node. If match found, if element to be searched is equal to a data which is present inside a node, in that case you are returning true. If complete singly circular linked list you have traversed and match is not found, in that case you are displaying that element is not present. So this is an algorithm to find out whether element to be searched is present inside singly circular linked list or not. Now suppose this is singly circular linked list containing five nodes with nodes as 2, 5, 7, 8 and 10 and head is pointing to first node that is true. Suppose I want to search element 8 to check whether 8 is present inside singly circular linked list or not. How you are checking? First you use or declare a temporary pointer which will point to the first node. Traverse in the forward direction and compare every time element to be searched with a data part. So first time 8 is compared with 2, match is not found, go forward then 8 is compared with 5, match is not found, go forward again 8 is compared with 7. So match is not found, go forward again 8 is compared with 8, this match found you are returning true here and you stop the searching and traversing. Now you can pause the video and you can answer in singly circular linked list what is the best and worst case time complexity for searching a node. You can pause the video and you can answer for this. Base case is big of 1 and worst case is big of n. Now in what case, best case we are saying when element to be searched is the first node. In that case number of comparisons required is only one. So within one comparison you can find out that element is present at the first position. So that is why this is the base case and complexity we are saying that big of 1 and what will be the worst case? Worst case is big of n, suppose singly circular linked list contains n element. So what will be the worst case? If element is not present inside singly circular linked list, in that case you are traversing the complete singly circular linked list, then only you are saying that element is not present or in other case if element is present in the last node. In that case again you have to traverse the complete singly circular linked list. So the worst case two scenarios, first one if element is present at the last node or element is not present inside a singly circular linked list. Now the algorithm for updating a node in singly circular linked list, again traverse the singly circular linked list from first load to the last node using temporary pointer. Remember what we have done for searching a node inside a singly circular linked list. Compare element to be updated with a data part of each and every node while traversing. Again you are comparing element to be updated or node which is to be updated with a data part of each and every node while traversing from first node to last node. If match found in that case you are updating the data part of that node directly. If complete linked list is you have traverse and match is not found for any node in that case you are returning minus 1. So this is an algorithm for updating a node in singly circular linked list. Now we will write two functions for searching and updating a node inside a singly circular linked list. This is a program, this program now contains insert at beginning which is already implemented and display which is already implemented. Search function we are writing now and update function we will write now. This is a main node driven main function where case 1 is for insert at beginning, case 2 is for display, case 3 is for searching, case 4 is for updating and case 5 is for exit. So first function we will write is search, this is your search function. First you declare the variables, this is struct node start time, this is a temporary pointer, this int element, you take the value of element from the user. So this is printf, enter value to be searched, then scanf, this is %d, address of element. You have stored that value inside integer variable element. Now initialize temp equal to start, use do while loop for traversing, you can use while loop also. So this is do, this is while, stamp is not equal to start, this is for complete one traverse. Now every time you are checking if the element to be searched is double equal to temp arrow data. In that case you are saying that printf element found or node found and then return. If match found you are printing that element found in the singly circular linked list and you are returning. Else what you are doing temp equal to temp arrow next, you are traversing. Now if after traversing if temp again reach to start, in that case element is not present. So you are checking if temp is double equal to start, in that case this is printf, this element is not present in singly circular linked list. We will execute this search function, then we will check whether this search function is working correctly or not. This is insert at beginning, suppose I will insert some values inside singly circular linked list N40 and then display. Now singly circular linked list contains 3 nodes 30, 40 and 50. Now suppose I want to search from this singly circular linked list, so choice is 3 for search and enter value to be searched suppose 40. Now it is printing that element found, means search function is working correctly. Now we will write update function here, similar to the search function. Again display all sorry declare all temporary variables, so this is struct node star temp then int element again printf enter node to be updated, this is slash n, scan f, this is percent d comma store that in element. Again temp equal to start, initialize temp to start, use do y look, this is y, temp is not equal to start, now check every time if temp arrow data, if that is double equal to element to be updated, in that case you take a new value which is to be updated from the user, so this is printf slash n enter new value and where you are storing directly in the node. So this is scan f, this is percent d comma temp arrow data, sorry store that at address of temp arrow data else if match not found you traverse temp to the next node. So temp equal to temp arrow next, that is it. So this do y loop will continue when it will stop when temp again reach to this start, I will execute this, I will insert some values, this is 50, again 140, again 130, if I call display function, so now singly circular linked list contains 3 nodes 30, 40 and 50, now I will enter choice as 4, I want to update 40 as 45, so enter node to be updated, I want to update node 40, enter new value suppose 45, now I will call display function, now 40 is replaced with new value 45, so this is my update function. So we have written two functions search and update, again we will move back to the presentation, these are some of the references I have used for creation of this video, thank you.