 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can write algorithm to search whether a particular brand is available in a linked list or not. Before starting, let me explain this diagram. Basically, we have three nodes and each node is having two parts. One is information and the second one is next to another node. This diagram I have already explained in my previous video. If you have not watched that video, you can find a link in the description of this video. In that playlist, you can find a video related to the production of single ideas. I am not going into the details of this. I am just starting the algorithm so that we can understand how we can search whether a particular element is available in a linked list or not. The name of the algorithm is search and the terms which I am going to use in this algorithm I am writing here. These are some values that I am going to use. So start with a point where we have a base address of node 1, then info is the first part of this node and link is the second part of this node which will be having the address of next node. Then aluc will be the variable which will be containing the location where the number is available. So it can be having two values, either null or any address. If number is not known, then aluc will be having null. If number is found, then aluc will be having address of that location where number is unknown. And item is the value that we need to search whether it is available in a linked list. So step number one, set ptr equals to start and aluc equals to null. So ptr is another variable which will be having address of node 1 that is right now available in the start function and we are initializing aluc with null. So if item is found, then this aluc value will be equals if number is not known, then aluc will retain as null. Now step number two, so after writing this step, I need to check, sorry I need to start aluc and then I will be checking the item. So will be step number three while ptr not equals to null. So if value of ptr is not equals to null, it means we can iterate this loop or you can say we have nodes in the linked list so that we can apply the searching process. So now I am writing step number three. So step number three will be if info of ptr is equals to item. So ptr, let's say ptr is equals to start from ptr maybe having value as 1001. So ptr is pointing to this first loop, first loop info part is 10. So if we write info ptr, it means we are accessing info part of that pointer location. So pointer location is 1001 which is node 1 and its information part is 10. Now we are going to calculate item. So let's say value of item is 20 that we are going to search. So right now info ptr is 10, item is 20 so it is not equal. Let's say if it is equal, so what happens if it is equal? Let's say item is 10 and this condition is 2. So in that case we can write set aluc equals to ptr. Because item is not on ptr location so that will be connected to aluc. So aluc will be having the address where that number is available. What you can say aluc is pointing to the node which is containing the item that we are going to search. And we can write exit. So it means we don't want to process this algorithm further. And we are currently in this algorithm execution side. So wherever you will be implementing a program based on this algorithm. So as one of the programming languages you can use the proper or appropriate statement here. So for example if you are implementing this algorithm with an epoxy language. So instead of using exit you can use break so that you can come out from the loop. So accordingly you can write a statement here while you will be implementing this algorithm with the help of any programming language. Now if this condition is false. Let's say item is 20 and info ptr is not equal to item. So in case of aluc we need to write the statement so that ptr can be moved to second node. So here we need to write set ptr equals to link of ptr. So item ptr is pointing to 1000. Its link or next part is having 2001. So that will be assigned to ptr. So new value of ptr pointing to 2000. And here we can write end of this. And you can write end of this. So now here is ptr. If ptr is not equal to none then there is condition to check. So ptr is not equal to none so it is 2000 but which is true. Now check info ptr. So ptr is pointing to 2000 and its info is 20 which is equal to item. So ptr will be assigned to aluc and this algorithm will be turned off. So this way this process will execute and let's say item is 40. So right now we have ptr that is 2001. Now info is not equal to item. And again ptr will move to link of ptr. So link of ptr is 3000 which is not equal to none. Again check info ptr that is 30 which is also not equal to item. Again we need to move ptr to link of ptr. So in this case link of ptr is none. So ptr will be having none. Now this condition is false. So you saw that if we want to search an item that is not available in the link list. So in that case this statement will not execute. So if this statement is not executing it means ptr is not assigned to aluc. So what will be available in aluc? Aluc will be continuing none. So if number is found that aluc will be having a particular address of a particular node where that number is present. Otherwise aluc will be equal to none. So wherever you will be implementing this aluc programming language. So you will be returning aluc and wherever you will be calling the backer you need to check the return value. If it is continuing none it means number is not found. Otherwise you just want a particular node. And at last you can write that number for aluc to end this aluc. So this way I implemented an algorithm to search a particular value in link list. And you can also implement linear search in link list. Because we are searching a location node by node. We are not searching a location entity. We are first searching the value of node 1, node 2, node 3 and node 4 and so on. So this is a linear process. So you can say this algorithm is implemented to apply a linear search on link list. So I will also explain you how we can apply a linear search on aluc as and this is called link list. So I hope you understood how we can write a linear search algorithm on link list. And if you want to watch more algorithms like linear search on aluc or other link list related algorithms. So you can go to description of this video. You will find links of playlist and you can follow those playlist where you will find all the videos related to data structures and algorithm. So do watch them and learn BSA. Thank you for watching this video.