 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So in this video, I am going to explain to you how you can write algorithm for linear search that can be applied on 1DL. So in my previous video that was also related to several algorithms like traverse, insert and delete related to 1DL. So after watching this video, now you can easily understand how we can implement linear search algorithm that will be related to 1DL. So here name of algorithm will be linear search and the parameters will be A, N, I, T, and L, O, C. So these four parameters are required. So here A is added with N elements, right? So N you can consider as total number of elements, those are available inside A and N. Then item is the value that we need to search. So item is to be searched. So we need to search whether this item is available in 1DL or not. And next is LOC. So LOC is the location where item is present, right? And if item is not available anywhere in the head, right? So in that case the value of LOC will be zero. So now I am going to write the stats. So in first step, I am initializing this LOC variable zero. So when you will be implementing a program or method for this algorithm, so you need to return the value of LOC to the caller method so that we can identify whether number was available in the adding or not. So if value of LOC remains zero after completion of whole algorithm, then it means element was not on. But if the value of LOC is other than zero, it means on that particular location, whatever the value is, the item is on, right? So this is the first step. So LOC equals to zero. Now, step number two. So step in, step number two, I am going to initialize a loop on that. So let's say I equals to one. So in my previous video I already told you, in case of data structure, we consider that first location of Eric is one, then two, three, four, five, six. And let's say these are the values which are available in Eric. So in case of algorithm, we are considering first location as one, but whenever you are going to implement this with the help of any programming actors or you are going to implement a method for this. So in that case, you need to start this I as zero and LOC you can initialize as minus. Right? So these little changes you need to do. Then after step number two, in case of step number three, we need to repeat a loop. So here repeat. So we need to repeat steps three and four. So step number, sorry, step number four and five will be repeated because three is the step. So step number four and five will be repeated and while I answer equals to n. Right? So this is the termination condition for this algorithm. So if I answer equals to n, then this loop will repeat and if I is greater than n, then this loop will be covered. Now inside this loop, we need to apply a condition. So that is if A of five equals to item. Right? So we are company A of five. So right now A of five is one a one position if it is equals to item. So it means item is found in that. So after this we can write set LOC equals to item. So on this location item is available and we can write exit. So exit is similar to break that we use in C programming to generate a loop. So here we cannot use breaks. So that's why I'm using exit. So if item is found. So I'm assigning LOC value of I and then. Right? And if this condition is false, then we need to move the loop counter to next position. So set I equals to I plus one. So this way I will move to second position then again this condition will be checked. If it is true, then that location will be assigned. And loop will be connected. And if it is false, then again I will be increment. So this way this loop will be and here I can write end of loop. Then. Stand number six. So after our termination of this loop. We can write exit. Now let's take an example so that we can understand it properly. So item that we're going to start with 13 and initial position of LOC is zero. Right? So I is one starting from here and it is six. So we need to repeat four and five steps. So I is less than equals to one. So this condition is true. Now check eight or five. So A of one position and item is 13. So it is false. So this step will not execute. Then I will be connected to value of five. Check this condition. It is true. It is true. It is less than equals to six. Then A of two position that is trial. If this equals to item, so no false. Again I will be implemented. So this time value of five is three. So again this condition is true. Check A of three position. So A of three position is 13 item is also 13. So this time condition is matching. So it will be executed. All of these will be assigned to value I. So I is right now three. So value of LOC will be three. It means at third location item is found and we need to exit this. So exit means the whole process. And your item location is three. So you can use this LOC area for further use. So value will be implementing this algorithm with any programming. So let's say you will be. So you need to implement a method and that method will be LOC with a value. Or you can say the location where that item was found. Let's say we are searching for 130 item is 130. So 130 is not available in the site. So in that case LOC will become zero. It won't be having any location. So in that case LOC will be returning zero. So in a column method where you will be calling the linear search method. You can check what is the value of LOC. If it is zero, it means item not found. If it is other than zero. So it means item was found at the location. Whose value is available in the LOC. So I know with this explanation to understand how we can implement linear search algorithm for what DNA with the help of data structure. So if you want to watch more data structure and algorithm related videos or data structure implementation with C language. So you can go to the description of this video where you can find links. And at the end of this video you can also find links of those things. So watch those videos so that you can understand data structure. And I hope you understood whatever I explained in this video. Thank you for watching this video.