Hello, everyone, welcome to this new video.
So in the last video, we have completed our air function.
So in this video we are going to write the code for the search function.
Right.
So in search function, it is very simple.
The code will be very similar to the error function.
What to do if you want to search a word or you just have to iterate just like we are operating here.
We will check whether it's present or not.
So, yes, it is present.
If it is present, you will go to that node.
Then it will check whether it is present or not.
If it is present.
Yes.
Or is present.
This is not right.
This is not normal.
So you will reach here.
Then you will check whether it is present.
Yes.
Is present.
Then you will reach here.
And finally we will come out of the loop and you need to check whether the last character is basically
a terminal or not.
If it's a terminal, you will return.
True, if this node is not terminal, then you will return false.
For example, if I want to find out are, then you will stop at R and it will check whether this is
terminal or not.
No, this is not terminal.
So since it is not terminal, so I will return.
False.
Simple, right.
And if there is a word that w vin so you will check whether the president does not know w is not present
in the area corresponding to the index w I am storing then.
So W is not present.
So right away you will return false from here.
Simple, right.
So this is going to be very, very simple code.
So let's just start writing the code.
Let's just jump into the code.
So the search function is going to be very similar to the error function.
So the search function will return, true or false, whether the given word is present in a dictionary
or not, so bold search again, what it will do, it will take a word which you want to search for,
and it will take a try in which you want to search the word.
So, again, we need to hydrate, so let's find out how many number of characters are there in the water
and let's hydrate.
So what to do, you know, to check whether the word is present or not.
Right.
For example, for every check, whether it is present or not.
So let's just check.
So every child.
Word of a.
Minus E!
So if this isn't an.
If this is an all that means it is not pleasant, if this is not present, then you can simply return
false from here.
You can simply return false, for example, for the given word.
If I want to search for one, then the blue is not present, right, only we have A and so W is not
present.
So right away you can return false.
And if it is present, for example, in case of Aries present, if it is present, you will go to that
word.
If it is present then you will go to that word sample.
Then you need to go to that world, so try.
Is it close to go to that world, which is child of Ralphy?
Minus a.
Simple and in the end, you will outrage over the complete world, and in the end, if the last character
is a terminal order, you will return.
False is the last.
Correct is not terminal three of the last terminal return true if not terminal return false.
So you can simply write.
And that's it.
So what I am doing here is I am taking for the last character, so if the last character is E, if the
last act I don't mean, then return true.
If it is not terminal, sordid and false.
So I am simply returning the value of this terminal and that's it, that our court is going to work,
our function is done, search function is done.
And I think we have inserted all the words in trial.
So yes, we have inserted all the words in try.
Now let's just check whether our search function will work or not.
Let's see.
So let's try to search for some words.
It's called a function such.
And let's say I want to search for Aadi and this is the try, so let's.
Right, Routier, similarly, let's search for other values also, let's call this basically.
Let's say let's give one more word, which is President Noize president here.
News is also present.
Let's give you a few words which are not pleasant, for example, when I don't know, no words.
Let's say ABC.
Let's say we are let's say X, Y, Z.
OK, so let's see what will be the output for this.
Let's send our called.
OK, some compilation errors.
And also, let's give a line here.
So that we can clearly visualize our output.
OK, so this is the output when, when, when, and then we have zero zero zero and zero, so let's
see what the output is, correct or not.
So I have three one one one one.
Then I have all the zero zero zero zero zero.
And so it is present in the dictionary.
Yes, no was presented a dictionary as news vice president.
The dictionary is when was not present.
ABC was not present e I was not present x rays.
He was not present.
So basically our try is working, our private sector is working properly and what is the time complexity
for searching.
So in this case, the time complexity is bigotry because at Max we will compare it.
You will compare or you will compare it.
So big of three.
Similarly for this big off two so we can say the time complexity for searching a void of size N will
be big off.
And so if there is a word which is containing incorrect correctness, then the time complexity for searching
is big off end.
And you can see creating this prie is basically a preprocessing work that we will do only one time.
Right.
This is a preprocessing work which will be done only once.
Once you have built that right, you will only search in that way.
Or if there is any new work, then occasionally you will do this, you will call the error function
of the tray.
So this preprocessing this is just one time work.
So let's not just include the time complexity for building or try because you will build a trial for
like thousands of legs of world.
So that's just one time.
That's just one time preprocessing and the rest of the time, but you'll be doing you will be calling
the search function so that this void is present in the scenario, not search this word, search that
word and so on.
So most of the time, ninety nine point nine percent of the time you will be doing the searching.
And occasionally, if there's any new word, you will be doing the information part.
So this is it from this video.
Guys, if you have any doubt and try, then you can definitely ask me in the Q&A section.
So this is it.
I will see you in the next one.
Thank you.