00:00The next question is to search in a link list.
00:03We will do it in an iterative way or loop.
00:06What do I want to do? I want to search a key in my link list.
00:10And then, I want to return the key to the position.
00:16And if the key doesn't get in the link list, I want to return to minus 1.
00:20Now, what is the way to do this?
00:23I have a link list which has been made in this way.
00:27I have data stored 1, 2, 3, and 4, and 5.
00:35So, I am pointing to each next and next node.
00:39And this is pointing to null.
00:41My head is here.
00:43So, what can I say in the beginning?
00:45If I want to insert a loop,
00:46the process of searching will be iterative.
00:50It means that I will go to one node and see what is here.
00:54Then, I will see what I have regionally.
00:57The view between eta is here.
00:57And in this node, I will see what I have.
00:59Then, we will see what I have regionally.
01:02In this node, I will see what I have regionally.
01:04How could I say that nuance as I have function in zooming transfers down into linear search?
01:11Using iterations.
01:12Let me add the value of my key.
01:14That is equal to 4.
01:15So first of all, I will take a temporary variable, node type, which I will initialize with head.
01:23So my node, temporary, is equal to my head.
01:27And I will increase this until my temporary is equal to null.
01:33Until my temporary is not equal to the last node, I will take my temporary.
01:41Every time I will check if my temporary data is equal to my key.
01:48If it is equal to my key, return it to true.
01:52Or I will return it to my index.
01:55I can take a new variable here.
01:58Int i is equal to 0.
02:01I can update it every time.
02:03And if it will not get me, I will update my index and temporary.
02:09So first of all, I will check if my temporary data is equal to key is not.
02:14So what I will do?
02:15I will update my temporary index.
02:18Temporary will come here.
02:19And i is equal to 1.
02:21Then I will check if my temporary data is equal to key is not.
02:26So I will remove it.
02:28I will take it here.
02:30Temporary i is equal to 2.
02:33I will check if my temporary data is equal to key is not.
02:37So I will update it again.
02:39I will update it again.
02:40I will take it on this node.
02:43Here will be i value as 3.
02:45Now I will check if my temporary data is equal to key is not.
02:48This data is equal to key.
02:50So I will return this index value here.
02:52I will check if my temporary data is equal to key is equal to 10.
02:58So what will happen in this case?
02:59My temporary data is also here.
03:03And here the temporary data is equal to i.
03:06The value is equal to 4.
03:07Now we will not match the key here.
03:09So we will add it again.
03:11And I will add it again.
03:13And I will add it again.
03:13Where the value is 6.
03:15As my temporary data is equal to 0.
03:17So what will happen in this loop?
03:20I will come out of this loop.
03:21And then I will return to minus 1.
03:23That my key does not exist anywhere in this link list.
03:27So the whole process and all these steps
03:29will be written in a form of code.
03:32I am going to make a function of my link list class.
03:33I am going to make a function of public int search.
03:37Or I can call it iterative search.
03:40We are searching from iteration.
03:42I am going to search for this key.
03:45So I will make a temporary node.
03:48Which I will initialize with the head.
03:50And then I will initialize with the integer.
03:52Which I will initialize with the 0.
03:54What will I do?
03:55I will run a loop until my temporary is not equal to null.
04:01I will check every time my temporary data is equal to my key.
04:08If temporary data is equal to my key.
04:11Then I will return to i.
04:13That means successfully my key has got.
04:16This is my key.
04:17Found case.
04:19No.
04:19Then I will update temporary data every time.
04:21To temporary data next.
04:23And every time i.
04:24I will do it plus plus.
04:25If the whole loop is finished,
04:27temporary value is null.
04:28Then I will not get the key.
04:30Then this will be my key.
04:32Not found case.
04:33In this case, I will return simply to minus 1.
04:36This is my iterative search.
04:37I will write code once again.
04:39My linkless is 1, 2, 3, 4, 5.
04:42Here I will call first.
04:45I will call iterative search.
04:49Linkless.IterativeSearch 3.
04:52And after that I will call linkless.IterativeSearch 10.
04:58Let's save and run.
05:02This was my linkless.
05:03This was my first index.
05:05This has given me the index of 3.
05:06Because it has got successfully in search.
05:08Which is at index 2.
05:10Then I have searched for 10.
05:11So it does not exist in my linkless.
05:14So in this case, I have a print.
05:15Minus 1.
05:16And this is the time complexity of iteration.
05:19Search time complexity.
05:21That is big of N.
05:22Linear time.
05:23Because I have traversed all the nodes in my linkless.
05:27To search for my key.