 So when we're dealing with any search method, we do have a few pieces of terminology that we do have to be mindful of The first one is obviously this sort of term known as completeness Again, if we're thinking about some of the more common ones that you've seen in data structures Does it actually get to a solution if one does in fact exist? That's sort of an important one if you think about it But again, if we think about sort of my example with the airports I can take the rdu to Charlotte to Chicago to Seattle routes That's gonna get me one potential solution or I might have found the longer one first I don't remember which airports were even in it and so that actually leads into sort of this question of it When we find a solution, is it the optimal solution because that is sort of important when we're dealing with choosing the best Actions and then when you sort of kind of think about it We get back into the the data structures 316 land where once again, we're having to deal with the idea of space and time complexity When it's doing these searches, how much memory needs to be taken place and then specifically if it is gonna get me the optimal solution Right, does it have to traverse every possible pathway to figure that out? So these types of things sort of become a little important Some other more terminology at least more when we start to turn this into some math for a second We do introduce a few different letters into mathematical equation B refers to this idea of the branching factor and if we're thinking about sort of an agent Especially our first little foray at the Rook or your your self-cleaning robot, right? I have an agent that is sitting in the middle Well, what is all the possible moves that that agent can do and for our sake? I'm making it a little simple. There's only four moves that they can do they could move up down left or Right and so when we start to think about those possible moves and at least get sort of in this perfect world We would say that it has a branching factor of a four and then we start to look at well when we're dealing with our Goal and what we're dealing with here is specifically this D If I'm looking for a goal, let's say again, this is my starting point and this is a potential goal point Well again, if we happen to have you know, just go left. All right Well, that's gonna get me there and we again say that that would be an optimal solution So the optimal solution would have a depth of one it only took one step to get to the goal But then we also have the maximum depth of the search spaces. Let's arbitrarily say that each one of these Again up down Lefts and rights that we could do from this potential state. So I went down Well, you know again, we'll arbitrarily say that yeah going down again Gets to our goal. Whatever it was get out of the box, right? Again, okay, we can see that going down gets us to their left right All of them will get me to the goal But specifically the big part here is this idea that what's the maximum depth as We're going through our search because again when we start to think about things like time and optimality again that maximum depth may come back to haunt us And so that's where I'll at least introduce to start a very simple One that you've seen from your data structures course. So data structures a little bit of a review Is this idea of a breadth first search? What we're dealing here dealing with here is this idea that when I work through a search So if I'm at my starting point and I want to sort of explore all possible sort of pathways I'm going to look at all of my possible steps Before digging any deeper so in my case of just an agent that can move up down left and right again I would branch out and see my four possible next steps And then I would follow that same process over again I'd see oh, you know if I take this first route. What can it see? Well, it can see four possible routes as well Okay, what about my next child? Well, it has four possible routes as well. What about my next child four? possible routes Again, and again, we can see this a little cleaner if we sort of walk through it And here's a little bit of a refresher on the algorithm You can pause the video here if you'd like to just copy it over But the big idea is that we're gonna be focusing on this idea of a queue or Something being first in first out again as soon as I see my children Those are the next ones that I'm going to be considering So let's use this as a little bit of a refresher this idea that I have a starting point I'm calling it a and I want to traverse through my nodes Maybe I want to find I or I want to find some goal that does not exist. So some goal That does not exist Notice there's no connection here. All right. Well once again notice I'm operating with the queue and notice I have a starting point going on here when I sort of Start my search. I start by adding in my starting point into the queue Because if we walk through the algorithm notice again, what happens is I'm asking specifically is the queue empty Oh, well, it's not because we just added that a Okay, well, what do we do? We are going to remove it from the queue and Do you know again from data structures? We always just sort of use the air quotes of visit But from our sake what we're going to do is we're going to grab all of the children of Sort of a and guess what they're gonna get added into our queue So again, I've added in my a not and that's mostly just to sign a signify a starting node So again a telling me what the node is Not simply just saying oh, this is my starting point. It started from nothing Okay, well again, we are going to remove a from the queue It's been visited and then notice a has in our case five children going again This is just sort of from a purely theoretical graph Suddenly I could go to node B node C node D node E and node H So in order that they were presented they are then added into the queue All right. Well, since I've added them all in I reach back to the top of the algorithm and I'm going to DQ B And that's exactly what I do. I've Removed B from the queue and well B happened to have its own Child node that it could work off of and so again, it's added to the queue again Since the queue is first in first out, it's going to the very bottom of that queue All right Well, we walk through the algorithm again We see that C is now at the top of the queue So it's gonna be the next thing removed and since it's the next thing removed We look at its children see it has a child we add G Here and notice again one of the things you're seeing here is sort of this idea that Keeping track of where I came from as well And that's sort of an important point as we start to try and figure things out again from we've achieved our goal How do I get to that goal? And so again, we keep on walking through this if C had a Another node attached to it. Let's say it was Z. Z would have came in And we would have just moved on just like normal either way We see that D from a is sort of the next thing in the queue You know the song and dance it gets removed D happens to have its own child I And so I is once again added to the queue and we continue to walk through this So again, we see II doesn't have any children. You could think of it like it. It is a dead end In a corridor and so okay. Well, we're done. So No, no other places to search H sort of the same way. I go up. Oh, there's nothing there. I go down Oh, there's nothing there. All right. Well, keep on searching with whatever's in the queue. We see F G and I they all do the same thing and again if we're thinking about it if I was the goal Congratulations, I found my goal I have a solution and since I knew where it came from again if we thought about these little points here We see that I came from D Well, where did D come from D came from a I know that a was my starting point and So my first step would be oh go to D but What happens if I don't have a goal, right? What happens if no goal was found? All right. Well what Brett first is going to be able to tell us what Brett first is able to say is if we've Traversed everything again, we've traversed all possible pathways and we were not able to reach a goal condition then in Sort of the sad fashion That goal is impossible to reach And so when we're looking at the idea of the Brett first search again We can go back to our sort of terminology Is it a complete search? Well, yeah, if a Solution is going to be solved or if a solution is able to be found awesome. It will find it Optimal yes, actually it will because again if we're thinking about sort of the Brett first search It's only looking one step ahead the entire time So eventually if I happen to find a goal Let me just draw this out here, and I'll I'll say the goals right here If the goal is able to be found again since I'm only making minimal numbers of steps Hey, I happen to have found a super cheap goal nice And so what's the time and space complexity? Well again if we're thinking about that be that's telling me my branching factor and Then D again was the optimal step So in our case it was it took two steps two in our case plus one again. This is sort of We may have better solutions So we may have to go through the entire thing of all of the breadth-first searches and that's a little bit on the Harrier side of things more to the point though is again. It shows a possible one step at a time Search Okay, well what would be sort of the exact opposite of this and again We're still in data structures land, and it's known as the depth first search Rather than say going only one step at a time We're gonna pull and dig and go down that rabbit hole until we reach what you could call a That's not how you write a D a dead end The entire idea is again you can see from the pseudo code What happens is I'm at sort of my starting location, and I'm going to say all right All right. Well, let me go ahead and say all right. I've gone through I hit my depth-first search helper. I Look at S. All right fine. I've looked into s and I mark it You know again, this is the visit Visit Description that we saw in the last algorithm But specifically notice it's saying all right. Well, what happens next and let's say again We're still working off of that branching factor of four. Let's go up Well again, what happens is I'm looking for sort of what's the node sort of at the end of this tunnel and then Notice I'm calling the depth-first search all over again If up has more possible routes if I can go up again Do that first I have not checked out down. I'm gonna keep on pulling on this thread Until I reach sort of a dead-end or the goal and when that happens What we do is if we reach a dead-end we introduce another term called Backtrack this is sort of where recursion comes back all of a sudden I'm gonna go from sort of my dead-end back to my parent and if my parent had More edges more pathways that it could take like that down It's gonna try and do it if this also happened to be a dead-end once again It's gonna backtrack and then try its next route as well So a way to think about this is now we're dealing instead of a cue we're dealing with a Stack again the idea here is something going to be first in but last out So you see all of a sudden again, I've drawn out the same little diagram and everything But I haven't visited a quite yet, right? I have not done that portion visit being I'm just sort of Deciding where to go. So again, I'm gonna remove a from my stack And I see that I happen to have again the same Possible pathways that I work off of but again, I'm dealing with a stack So the next element that gets removed is going to be be same as before But again being a stack first and last out when I get to be I'm gonna see that be has its own child and F is gonna go to the top of the stack and Notice again, I have sort of this little red dot following so to where I am where I Am Because again when we deal with that idea of dead-ends and backtracking I'm gonna sort of need to know that So again, I go down to F because F is the next thing in my stack So I go down to it, but I notice that F does not have any other pathways. So no other Moves from here and this is not my goal. Well, what do I do? So I'm going to do Backtracking this idea that from F. Well, where did F come from F came from B? So let me go back to be Backtracking well B also has no other paths other paths So I'm going to backtrack again. I'm gonna go from B and say well, where did B come from? Oh, it came from a let's go back to a and as you can sort of see while a has more children So it's gonna go to see see has a child. It's gonna go to G We backtrack again because G was another dead-end C has no other possible pathways So I go back to a I go to D and we repeat the process over and over again I won't spare. I'll spare you sort of going through it again But sort of when we look at sort of those properties now we ask some questions Is the depth first search a complete search? That's where we get into a little bit of an issue because Technically speaking a depth first search could lead to infinite loops a way to think about that is again Let's draw out sort of our three by three grid And let's arbitrarily say I happen to have another Column and let me add a little bit of a We'll call it a wall right here Well, you notice that again if I go up it's gonna take me one direction if I go down it's gonna take me the other But more specifically again when we think about this idea of something potentially having infinite loops You notice that I could in theory follow this chain That's gonna lead me to sort of this point. All right, not terrible. I could have got there Easier, but if I keep following suit if I don't have a mechanism to sort of stop those infinite loops I could just go in a circle the entire time around this grid because Again, I can and so that actually leads to the idea of it. Is it possible to or is it an optimal solution? also no actually because again if we're thinking about this what if this was our goal point and We started from this node and we walked all the way sure We would have found a goal But as you can imagine it's not gonna be as good as going up and into the left again This depends on which action you're taking first and so when we think about its space and time complexity We run into that sort of Ugly in again think about that as the maximum depth Because again, I could potentially Exhaust all Possible moves that I'd need to do to get here So again if I went down and I'm taking the worst possible solutions that M would take me one two three four five six seven eight moves I Am equaling eight rather than the optimal solution So the optimal solution was the two we're not taking that two We're having to go all the way around so again It's a trade-off of what we're dealing with here But hopefully that was an introduction to uninformed and depth first in the next video We'll actually see a little bit of sort of a marriage between the breadth first and the depth first known as iterative deepening search