1 00:00:01,110 --> 00:00:03,160 Hello, everyone, welcome to this new video. 2 00:00:03,180 --> 00:00:06,170 So in the last video, we have completed our air function. 3 00:00:06,390 --> 00:00:09,870 So in this video we are going to write the code for the search function. 4 00:00:10,410 --> 00:00:10,780 Right. 5 00:00:11,010 --> 00:00:13,170 So in search function, it is very simple. 6 00:00:13,410 --> 00:00:15,450 The code will be very similar to the error function. 7 00:00:15,450 --> 00:00:21,750 What to do if you want to search a word or you just have to iterate just like we are operating here. 8 00:00:21,930 --> 00:00:23,880 We will check whether it's present or not. 9 00:00:24,150 --> 00:00:25,650 So, yes, it is present. 10 00:00:25,650 --> 00:00:28,170 If it is present, you will go to that node. 11 00:00:28,710 --> 00:00:30,780 Then it will check whether it is present or not. 12 00:00:30,780 --> 00:00:31,970 If it is present. 13 00:00:31,980 --> 00:00:32,369 Yes. 14 00:00:32,369 --> 00:00:33,240 Or is present. 15 00:00:33,270 --> 00:00:34,800 This is not right. 16 00:00:34,860 --> 00:00:35,720 This is not normal. 17 00:00:36,000 --> 00:00:37,290 So you will reach here. 18 00:00:37,830 --> 00:00:40,140 Then you will check whether it is present. 19 00:00:40,150 --> 00:00:40,530 Yes. 20 00:00:40,530 --> 00:00:41,280 Is present. 21 00:00:41,280 --> 00:00:42,770 Then you will reach here. 22 00:00:43,350 --> 00:00:50,280 And finally we will come out of the loop and you need to check whether the last character is basically 23 00:00:50,280 --> 00:00:51,470 a terminal or not. 24 00:00:51,720 --> 00:00:53,460 If it's a terminal, you will return. 25 00:00:53,460 --> 00:00:57,130 True, if this node is not terminal, then you will return false. 26 00:00:57,480 --> 00:01:02,820 For example, if I want to find out are, then you will stop at R and it will check whether this is 27 00:01:02,820 --> 00:01:03,610 terminal or not. 28 00:01:03,630 --> 00:01:04,870 No, this is not terminal. 29 00:01:05,190 --> 00:01:07,590 So since it is not terminal, so I will return. 30 00:01:07,590 --> 00:01:08,100 False. 31 00:01:08,940 --> 00:01:09,830 Simple, right. 32 00:01:09,960 --> 00:01:18,420 And if there is a word that w vin so you will check whether the president does not know w is not present 33 00:01:18,780 --> 00:01:22,320 in the area corresponding to the index w I am storing then. 34 00:01:22,650 --> 00:01:23,850 So W is not present. 35 00:01:23,880 --> 00:01:26,180 So right away you will return false from here. 36 00:01:26,640 --> 00:01:27,420 Simple, right. 37 00:01:27,690 --> 00:01:29,880 So this is going to be very, very simple code. 38 00:01:29,910 --> 00:01:32,140 So let's just start writing the code. 39 00:01:32,160 --> 00:01:33,920 Let's just jump into the code. 40 00:01:35,820 --> 00:01:39,000 So the search function is going to be very similar to the error function. 41 00:01:40,370 --> 00:01:45,620 So the search function will return, true or false, whether the given word is present in a dictionary 42 00:01:45,620 --> 00:01:50,810 or not, so bold search again, what it will do, it will take a word which you want to search for, 43 00:01:50,990 --> 00:01:54,080 and it will take a try in which you want to search the word. 44 00:01:57,530 --> 00:02:05,120 So, again, we need to hydrate, so let's find out how many number of characters are there in the water 45 00:02:05,990 --> 00:02:07,220 and let's hydrate. 46 00:02:13,430 --> 00:02:18,260 So what to do, you know, to check whether the word is present or not. 47 00:02:18,290 --> 00:02:18,680 Right. 48 00:02:18,920 --> 00:02:22,170 For example, for every check, whether it is present or not. 49 00:02:22,520 --> 00:02:23,820 So let's just check. 50 00:02:24,230 --> 00:02:26,870 So every child. 51 00:02:27,830 --> 00:02:29,000 Word of a. 52 00:02:30,360 --> 00:02:31,380 Minus E! 53 00:02:32,250 --> 00:02:33,360 So if this isn't an. 54 00:02:36,110 --> 00:02:41,060 If this is an all that means it is not pleasant, if this is not present, then you can simply return 55 00:02:41,060 --> 00:02:41,780 false from here. 56 00:02:44,000 --> 00:02:47,540 You can simply return false, for example, for the given word. 57 00:02:48,430 --> 00:02:54,160 If I want to search for one, then the blue is not present, right, only we have A and so W is not 58 00:02:54,160 --> 00:02:54,470 present. 59 00:02:54,490 --> 00:02:56,040 So right away you can return false. 60 00:02:56,440 --> 00:03:03,070 And if it is present, for example, in case of Aries present, if it is present, you will go to that 61 00:03:03,070 --> 00:03:03,400 word. 62 00:03:04,150 --> 00:03:07,240 If it is present then you will go to that word sample. 63 00:03:10,710 --> 00:03:14,640 Then you need to go to that world, so try. 64 00:03:16,550 --> 00:03:23,030 Is it close to go to that world, which is child of Ralphy? 65 00:03:24,140 --> 00:03:25,600 Minus a. 66 00:03:27,460 --> 00:03:34,930 Simple and in the end, you will outrage over the complete world, and in the end, if the last character 67 00:03:34,930 --> 00:03:36,400 is a terminal order, you will return. 68 00:03:36,400 --> 00:03:37,680 False is the last. 69 00:03:37,680 --> 00:03:43,290 Correct is not terminal three of the last terminal return true if not terminal return false. 70 00:03:43,510 --> 00:03:45,040 So you can simply write. 71 00:03:49,810 --> 00:03:50,530 And that's it. 72 00:03:51,100 --> 00:03:56,890 So what I am doing here is I am taking for the last character, so if the last character is E, if the 73 00:03:56,890 --> 00:03:59,110 last act I don't mean, then return true. 74 00:03:59,110 --> 00:04:01,160 If it is not terminal, sordid and false. 75 00:04:01,420 --> 00:04:08,170 So I am simply returning the value of this terminal and that's it, that our court is going to work, 76 00:04:08,470 --> 00:04:10,750 our function is done, search function is done. 77 00:04:11,230 --> 00:04:14,980 And I think we have inserted all the words in trial. 78 00:04:15,030 --> 00:04:17,300 So yes, we have inserted all the words in try. 79 00:04:17,680 --> 00:04:21,370 Now let's just check whether our search function will work or not. 80 00:04:22,019 --> 00:04:22,540 Let's see. 81 00:04:26,080 --> 00:04:29,320 So let's try to search for some words. 82 00:04:35,640 --> 00:04:37,310 It's called a function such. 83 00:04:40,640 --> 00:04:48,470 And let's say I want to search for Aadi and this is the try, so let's. 84 00:04:49,880 --> 00:04:59,870 Right, Routier, similarly, let's search for other values also, let's call this basically. 85 00:05:21,820 --> 00:05:26,080 Let's say let's give one more word, which is President Noize president here. 86 00:05:31,090 --> 00:05:32,750 News is also present. 87 00:05:34,780 --> 00:05:40,240 Let's give you a few words which are not pleasant, for example, when I don't know, no words. 88 00:05:42,320 --> 00:05:45,410 Let's say ABC. 89 00:05:46,410 --> 00:05:51,960 Let's say we are let's say X, Y, Z. 90 00:05:53,050 --> 00:05:56,320 OK, so let's see what will be the output for this. 91 00:06:03,680 --> 00:06:05,000 Let's send our called. 92 00:06:11,130 --> 00:06:13,140 OK, some compilation errors. 93 00:06:21,980 --> 00:06:24,890 And also, let's give a line here. 94 00:06:40,640 --> 00:06:43,280 So that we can clearly visualize our output. 95 00:06:55,650 --> 00:07:03,540 OK, so this is the output when, when, when, and then we have zero zero zero and zero, so let's 96 00:07:03,540 --> 00:07:05,350 see what the output is, correct or not. 97 00:07:06,120 --> 00:07:09,720 So I have three one one one one. 98 00:07:09,730 --> 00:07:13,130 Then I have all the zero zero zero zero zero. 99 00:07:13,150 --> 00:07:16,040 And so it is present in the dictionary. 100 00:07:16,050 --> 00:07:19,490 Yes, no was presented a dictionary as news vice president. 101 00:07:19,510 --> 00:07:21,720 The dictionary is when was not present. 102 00:07:21,720 --> 00:07:24,870 ABC was not present e I was not present x rays. 103 00:07:24,870 --> 00:07:25,740 He was not present. 104 00:07:25,750 --> 00:07:32,760 So basically our try is working, our private sector is working properly and what is the time complexity 105 00:07:32,760 --> 00:07:33,440 for searching. 106 00:07:33,630 --> 00:07:38,450 So in this case, the time complexity is bigotry because at Max we will compare it. 107 00:07:38,480 --> 00:07:40,290 You will compare or you will compare it. 108 00:07:40,470 --> 00:07:41,370 So big of three. 109 00:07:41,670 --> 00:07:47,940 Similarly for this big off two so we can say the time complexity for searching a void of size N will 110 00:07:47,940 --> 00:07:48,690 be big off. 111 00:07:48,690 --> 00:07:57,570 And so if there is a word which is containing incorrect correctness, then the time complexity for searching 112 00:07:57,570 --> 00:07:59,010 is big off end. 113 00:07:59,280 --> 00:08:06,380 And you can see creating this prie is basically a preprocessing work that we will do only one time. 114 00:08:06,390 --> 00:08:06,780 Right. 115 00:08:07,500 --> 00:08:10,680 This is a preprocessing work which will be done only once. 116 00:08:11,940 --> 00:08:15,510 Once you have built that right, you will only search in that way. 117 00:08:16,020 --> 00:08:21,930 Or if there is any new work, then occasionally you will do this, you will call the error function 118 00:08:21,930 --> 00:08:22,590 of the tray. 119 00:08:23,280 --> 00:08:26,640 So this preprocessing this is just one time work. 120 00:08:26,940 --> 00:08:32,640 So let's not just include the time complexity for building or try because you will build a trial for 121 00:08:32,640 --> 00:08:34,799 like thousands of legs of world. 122 00:08:35,340 --> 00:08:36,659 So that's just one time. 123 00:08:36,659 --> 00:08:41,370 That's just one time preprocessing and the rest of the time, but you'll be doing you will be calling 124 00:08:41,370 --> 00:08:46,800 the search function so that this void is present in the scenario, not search this word, search that 125 00:08:46,800 --> 00:08:47,760 word and so on. 126 00:08:48,060 --> 00:08:52,680 So most of the time, ninety nine point nine percent of the time you will be doing the searching. 127 00:08:52,680 --> 00:08:56,600 And occasionally, if there's any new word, you will be doing the information part. 128 00:08:57,510 --> 00:08:58,950 So this is it from this video. 129 00:08:58,960 --> 00:09:03,780 Guys, if you have any doubt and try, then you can definitely ask me in the Q&A section. 130 00:09:04,170 --> 00:09:05,130 So this is it. 131 00:09:05,130 --> 00:09:06,720 I will see you in the next one. 132 00:09:06,720 --> 00:09:07,320 Thank you.