 So like I said in the last video we have this issue that you know the breadth-first search It's good But it may take us quite some time because we have to explore all moves one step at a time And then we have the depth-first search which unfortunately could lead down rabbit holes But we may get into sort of non optimal solutions and so to sort of introduce a Another type of search to you. I'm introducing something called the iterative deepening search Now if we sort of look at the terminology is it complete? Yes again Just like the breadth-first search if a solution exists it will be able to find it Optimality well one of the things that we're doing with that that big fancy five dollar word here iterative is we're sort of mimicking the behavior of one step at a time and so yes, we can still get The shortest path and we actually do so in a slightly shorter Time then we would with either breadth-first or depth-first by themselves Okay, so what is iterative deepening search the entire ideas we are going to do do Or that's a terrible way to write that do depth first search with a limit on number of moves That's it in a nutshell. We are simply going to say that just do DFS but you're only allowed to Make say one step or three steps and that's it and if you can't find the solution in that many times We'll get there So again, what we do is we actually start at a limit of zero what we're essentially saying here again with limit zero is How many? moves Can I Make All right Well the limit of zero is simply saying all right given my starting location am I at my goal and let's arbitrarily say again You can sort of see here is my goal. My goal is gonna be Goal so again when we're dealing with iterative deepening search, we're looking at this limit zero and saying well am I at the goal? A no, no, I want to be at E. So what do I do well rather than concluding that the search is frivolous what I'm going to do is Increment that limit by one What one means is again, I'm allowed to have one Step in my DFS and so when we think about that one step All right Well again, I'm at my starting point of a and again, I'm going to do depth first search So I look at B because that is a connection All right. Well once again, I asked that question am I at my goal? No, so all right Well, you could think about it like I had one move available Here's my one move All right. Well again, I asked myself am I at the goal? No, so again, we're still doing DFS but now with one step so since we have exhausted this Pathway, we're gonna once again backtrack. Oh I have one step available again. So all right. Well does a have other pathways? Yes, it does. It has a pathway to see Let's check that pathway. Am I at my goal? No, again, my goal is E So again, we've not found our solution at this point. Let's backtrack again. Oh, I have one more move I can do do I have any other possible routes? No. Oh, okay. Well What do we do? We are simply going to increment limit again and So now when we are do our DFS is we get two steps So again, I have two moves from a I'm gonna take my first move to be That was one move. I get one move left. All right. Well, where can I go? I'm I have a pathway I can take so let me take it D again. That was my last move I might add a dead end effectively. So what am I going to do? I'm going to backtrack and I get one move. Does B have any other routes? No, it doesn't so I Backtrack again. Oh, well a I have two possible moves. A has potential pathways. I can go Let me go down them. So I here's my first move down to C I'm gonna do my second move to F. No. Oh darn. Well, again, I'm at a dead end I backtrack to a I have new two moves, but I have no spaces left to go I have not found my goal one more time. And so one more time I'm not gonna write it out, but one more time. I increment by one and So once again, we're going to see this in action So I'm going to go to a I go to start from a to B to D to E I see that E is my goal. And so how did I get there? Well from E I had to go to D from D. I had to go to B or from to get to D I had to come from B to get to B I had to come from a and so I can see that this a to B would be my first step along the way So just as a sort of group exercise, I'm gonna work through sort of the iterative deepening search So you can sort of see this in action. So my first one again, I'll work off of that limit of zero Just to illustrate it Congratulations, we're done. No, we clearly know that this is not gonna be helpful So I have to do it again. So this time I've incremented and I'll change my color back I'm gonna increment that my limit is Equal to one I get to make one step again from a I see that I can go to B And that's my one step. So I backtrack to a so I backtrack to a I See a has another pathway. So I'm gonna go from a to C Again, I'm still not at my goal of G. So I backtrack back to a A has no more pathways. So I'm at a dead end again. What do you know? We got to increment to two now for my sake, I am gonna erase it one more time because Just for our drawings perspective. So again now we're at a limit of Two again, we're starting at a I have my first move going to be All right, B has a pathway that it can take and I have one move available So I'm gonna take that D pathway All right, well D wasn't my goal. So what do you know? I'm out of moves as well. So I backtrack to be Backtrack to be B has no other pathways. So I'm out of moves effectively backtrack to a I got two moves left I can go to C Now notice C has two possible pathways When we refer to that idea, I've said in a previous video of I'm not gonna traverse previously traverse nodes What I was actually referring to is in a pathway So again this Route was a pathway This next route, let me change colors again this a To see to D This is a completely separate pathway. So yes, I'm going to traverse D again, but notice sort of where this is coming from when I was traversing B. I didn't go You know to a right. I didn't do this. We that was what we were referring to when I'm not gonna Traverse previously traverse nodes a was where I came from or is one of my ancestors. So I'm not gonna do it That you know just to sort of refresh your brains on that but just to move aside for a second. Let me Scribble that out D again didn't have the pathway. So I go back to C. C has another route that I could go which is E E isn't there. So again, I've got a backtrack from E to C because I only got two moves C has no other path. So I backtracked a I get I have two potential moves, but I'm out of moves So again, I have not found my Goal so all I'm going to do is Increment my limit by three. So that final time one last time around the block. I've got my limit Equal to three. I start at my a node. I can go down to my b node. I Can go from my b node to my d node and Again, now this is an interesting point because I get three moves here was one here was two I get my third move from D D has two routes. I could either go To see well C didn't work out for me. It's a dead end. So I backtrack D can go to E E is still a dead end. So I backtrack D has no other moves that I can do So I backtrack to be B has no other move. So I backtrack to a a I have three moves I can do so I go down to C C is another pathway C has two possible routes I can go down the D route again. We're doing depth first search We have to carry it all the way through and D has two possible routes that it can work off of It could either go B and again that didn't work out for us So we backtrack and it can go E and then just like we saw in the other pathway Well, he didn't work out for us either. So we backtrack D has no other moves So we go back to C and we go to E All right. Well, he happens to have three possible routes that it can work off I'm gonna do them in alphabetical order just because it's a learning Exercise but again, you know, that's an arbitrary choice on my sake. So again, this was move one move to move three I check D D didn't work. So I'm going to backtrack to E E has another move It could take F. Well F is again the dead dead end So it backtracks to E and then finally I get to G in our case G is the goal And I've reached my goal with a limit of three