 So if we look at all the videos we've seen so far the breadth first search the depth first search the iterative deepening search The bi-directional search each one of those were falling under the banner of what we called an uninformed search and the entire idea is with an uninformed search You know, I'm just kind of shooting out into the dark and hoping that one of my pathways may lead to My G. All right, and I don't really know how far each one is getting me closer I don't know if this step is getting me any closer to G than this step and that that idea of getting closer That's actually where we introduce the idea of an Informed search and specifically we have to start introducing more Formulas if you will So what we're looking at when we deal with sort of informed searches is what we call sort of our Evaluation function this idea of an f of n given some in some node Some node that I am currently at. What is the desire ability of going desire? ability What is the desire ability of going to this node? so if we thought about it again with that idea of, you know, my Kind of for I think I'm doing a five by five if I had a starting point and I had a goal You know, I had some node moving to the right then I'm just gonna draw it like this I'm effectively saying. What is the desire ability? design Desire ability of moving Right And it's through this f that we can actually utilize and make some more informed decisions Because we can start to utilize some of those different data structures that we've seen in our previous courses Specifically something known as a priority queue something, you know, if we associate different values to these different possible steps So this step versus this step each once again going to have some desire ability associated with it and I could make a decision where say for example moving down is Better than moving to the right. So how do we do that? that's where we get into this idea of path scoring and Specifically we have to break our desire ability our f function into two other sort of terms G and H When we look at G the idea here is how far have I gone already? so if we're thinking about sort of that s and Looking at the different branch ways if I only did a three-step for the sake of drawing You know boom And boom when I get to sort of this Point my G would have equaled to that's a G not an s the entire idea is oh I had to make one step two steps I had to go two steps in this direction to get here But that actually leads to again the idea of H So G may be good again this idea that maybe I want to minimize my steps and so I want to allow G but H is then saying well again, I'm Searching for some goal and there's some pathway to that goal. So given this point There's this mythical sort of connection between us Can we estimate how much further I have to go to get to G? And you can sort of see this in action, you know again I have an s that has two potential pathways one moving to the or upward and then one Moving to the right. Well, both of them again are going to have this G Equaling one I've made one step in sort of my search But then we're also asking sort of the question of well, what's their H? And that's where you know, we'll see this in a little bit of our talks over the next few videos This H is what we call a heuristic It's an estimation and so because it's an estimation there are a number of possible Kind of math algorithms you can use to make that estimate and one that I'll at least sort of introduce a sort of a very Simple basic version is known as the Manhattan distance method and the entire idea is it's inspired by the different blocks and streets and intersections of Manhattan in New York and the entire idea is well I go up into the right or I'm Going sort of in linear motions only so I can only go sort of up down left and right When we think about this sort of wall, so this is a wall right here This estimate does not care about it. It's just saying, you know what? It's just another step along the way because we'll you know, obviously when we are making decisions We know that we can't go through the wall So as a result we just sort of again treat it as it's another step along the way One way to think about this is go all the way back in time to when you were learning about slopes Specifically you learned that there was an M slope and then you know your instructor Probably used some idea of a rise then run To describe it the entire idea again if you thought about it, you know M We use sort of this fraction of going oh, you know, I rise one I run six in our case rather we're going to say that that one That one is our G and then that six is Is our H and so rather than turning it into a fraction, right our F for any given node again if we're looking at say a five so my my F of a five Would have been oh well a G of one because it's only taking me one step Plus using Manhattan distance. It would take me one two three four five six Potential again, we're making only an estimation six potential moves to get to my goal conversely if I wanted to look at F of B six B six Again, it's only one step So G is gonna be the same and we would do the same sort of calculation So it would take me one two three four five six as well All right. Well, just to kind of make it a little slightly different. Let's arbitrarily say I Use this one as a better sort of source Let's say G was not here, but rather it was sitting right here Okay, well again, how many steps would it take my F of a five Again is still going to take one step. So my G is still one plus how many moves would it take from a Five to get to our goal a one one two three four and Then if we looked at my F from B six again, it's only one step Well, how many moves does it take one two three four five out six? And so if you then calculated those out a five versus B six. Oh Well, you know this one happens to be the cheaper of those two and since we can use something like a priority cue to Make a five come to the top of our cue. Oh, that's the route. I should explore next Another type of heuristic that you could use is something known as the straight line Distance formula or literally the distance between two points This works a little bit better if we're dealing with situations in our case when we don't have a grid structure So I'm just sort of using a much more cleaned up map From my previous videos because again, I want to make this, you know, slightly easy to kind of manipulate but if we're looking at it each one of my different airports has a sort of Estimation of how far it will go my estimation was I popped in these airports or these city names into Google Maps and Then I recorded how many miles it would take to drive from say Atlanta to Seattle Okay Well, if you notice These are just producing some kind of value to them and we can still do that same idea of the G plus H If again, we're looking at it from Rdu's perspective so the f of say for example going from Rdu to Charlotte well that would take again 167 steps to get to Charlotte and then well We would just look up that little calculation or that that heuristic and that's two seven nine five And I'm not going to do that math off the top of my head So as a consequence again, we see that we have a score and we can compare that score to other scores and That introduces us to the idea of a star path finding We utilize again that G and that H to make those evaluations So how do we kind of work through this? Let's say again? I'm working off of the notion that I want to work off of Raleigh to Seattle. Okay? Well again, I'm working instead of it being a Q or a stack. I'm working off of a Priority Q and The entire idea just to kind of refresh that very shortly is as I add elements in to the priority queue So let's say that's a six that becomes a seven. That's an eight That's nine as I add in say for example a two Since I see that two is less than my parent. What we can do is something called bubbling up I can swap this two in this seven so this Would become the seven this would become a two and When I do a comparison like that again again We're slowly moving our highest priorities or in our case the lowest priorities to the top of our queue I Can remove or I can swap out that five in that two so five goes there two goes there What this is again allowing us to do is again see oh well since I know I can access the root of my priority queue That's gonna turn into in our case Where we go next so in our case we start off I Like to draw this kind of format out so this idea you see I have where I'm coming from Again, this is helpful when we're sort of making our decision of how we make our moves To some given location since we're starting at rdu You know this is a knot. This is it's null. It's it's none. It's whatever we want as sort of our algorithm Same kind of things going on with our G since we are starting here. We don't need to move here It's not gonna cost us anything to move here because we're already here But we still ask that same question. How much further do we have to go because we're already in the a star algorithm? So we see that it would take us 2844 sort of miles if we were to just drive from here straight through don't care about anything else And so that gives us the f score 2844 okay, so we just established our starting point. What happens next? Well each one of the moves or the airports that we can work off of from rdu so in our case Dallas or not Dallas Washington DC Charlotte or Atlanta those are the only three that I made for this little example Those get expanded upon and again, we're looking at specifically. I like to sort of add in What the G's are for each one of these pathways? This just helps my brain sort of keep everything together And you notice I'm just sort of following alphabetical order as I add them in and this is mostly just for my sake of I Gotta do a lot of math. So I'm not going to do I'm not gonna try and figure it out then add them to my visualization I'm just gonna add them in a certain way But one of the things again, you're noticing is well to get from rdu to Atlanta. It would take 407 miles all right So we're going to go ahead and say that that's our g and then we ask the heuristic Well from Atlanta. How far would it be from Seattle? And that's 2600 well, we guess what we add those two together That's gonna give it an F score of just over 3000 3000 miles in this case. Okay fair. That's one out of my three possible routes So I'm gonna check next. What do I do with Charlotte? Charlotte it's much closer to rdu and only takes me 167 miles to get there. Okay fair And you know, it's a little further away from from Seattle than Atlanta, you know, Georgia versus North Carolina So it's a little further about a hundred miles more. So we add them together and you're gonna notice. Oh 2900. Okay, we're not done. We we still have to do Washington DC and we do and we see that it's Very very much just under 3000. So what happens? Well, again, think about it like it's a priority queue I added in sort of this 3044 that should be a four I Then added in the 2960 2962 Because of how the priority queue works It did a comparison to its parent and it sees. Oh, well, guess what? You're you're cheaper. So you have higher priority So in the sort of structure itself This became 2962 and this became 3044 44 then as we added in Washington DC, it was 307 we did that same comparison We didn't see that it was a cheaper route or a higher priority And so it just stays where it was So we adjust. Okay. Well, we see. Oh, you know Charlotte is the Cheapest next step. So let's look there first Specifically I used a word there Look there first. We're still in the planning mode. We are we have not left Rdu We're just considering and thinking about all our possible routes. Okay Well, we go to Charlotte and then what happens? Well, you jump all the way back to the Charlotte slide or the airport slide that had all the pathways from Charlotte I'm just gonna click through I do drop out the numbers because then it gets a little uglier But you can see that what I did is I sort of added in all the different pathways They're already in order just for the sake of ease But one thing I did sort of leave out is how we calculate out these second step G's one of the things we have to do is we are still considering How much we've already gone remember? That's the point of G. How many how how much have I already done? So when I look at say for example Charlotte to St. Louis, St. Louis would have been 715 miles what I'm dealing with is a G of 167 plus 715 H hasn't changed. We're still utilizing that same Straight line heuristics. So we again go all the way down and we still see that it is You know in this case 2083 we add those we add the G and the H together and we pull out the 2965 and that's it You can see we do that with each one of these kind of pathways and that's sort of an interesting point notice in our case even though sort of in my examples before Shar Chicago hair was sort of the the quick route St. Louis is actually pulling ahead right now. And so we do have to again consider This before we can consider this and so again, that's exactly what we're doing You can see I'm just sort of Walking through these steps. You can take a moment if you want to work through this on your own Go ahead and sort of pause through this But again, we see so St. Louis is the next cheapest route So it's the next thing that gets pulled out of the priority queue and we expand on it And we get Kansas City or once again O'Hare so again same kind of concepts going on we add those to the queue You can see that we're still sort of making the calc I've made these calculations And so this brings up an interesting point because once again the queue is going to move these to their respective locations because obviously this 3700 is lower priority than 29 and a 32 so oh well what happens in our case notice I Have a tie technically I could compare Charlotte to O'Hare or I could Compare St. Louis to Kansas City. They both are going to give me the same F And so what do I do in this situation? Do I leave it as is and so in our case if you were here first you have higher priority or if you are a new sort of Addition to the queue you're added ahead That's effectively going to be the difference between I'll call it node a being let me That's sort of the difference between node a being less than node b Versus node a being less than or equal to node b It's really in essence. Which one of these comparison operators does your comparison function do? And so in our sake I'm going to work off of the O'Hare one It was first in the queue, you know that just makes sense to me So again O'Hare is the next one out of our little position. And so what do we do? We expand on all of O'Hare's possible routes So I am dropping out some of these because again, I'm trying to make this at least a little readable But if you feel like it you can Calculate them all out. And so again, we start to see but notice even though O'Hare was added in and Because O'Hare has a connecting flight to Seattle. Oh, I can taste it. I can I can taste that This is right it within distance Just like we've seen in our other searches just because it's in the queue for consideration doesn't mean it's A valid solution. We haven't made that decision yet. We haven't made that step We still have to make our expansion from st. Louis to kansan city first So we have to and we walk through it and we see that yes, even though It you know Leads to nothing this it was the next thing that needed to be considered We see that kansas city to atlanta and then to salt lake city Both of these are not that great Let's see salt lake city kind of gets me closer So you can see that one of them does make it to the the visualization And it's all right, you know, it's What fifth in the queue we may consider it again It's it's higher up there than some you know than going back to atlanta But again, we just continue to walk through the algorithm But as you clearly see once we get to the next item in the priority queue We go from o' hair to seattle seattle is our goal condition And we've done a star search congratulations Now what oh well, you know again, I'm still here. I'm still at rdu So I still have to technically make my first move. I still have not done that So how do I do that? And that's sort of where I was making these twos and forms Why was I doing that because what was the parent? From seattle because I found my goal. How did I get there? Oh, well to get to seattle. I had to come from o' hair To get to o' hair. I had to come from charlotte to get to charlotte I had to come from rdu. Hey, wait a minute That's my start Oh, well happy days since I know that rdu was my starting point This is the action I should take I should move in this case to charlotte And once all this is said and done You do it all over again. I have to do the same comparison now from charlotte to seattle Well, why well for you know airports, they don't move that often. It's not going to be terrible To kind of calculate it once and be done with it and just save your path But sort of the way to think about it is What happens if I'm dealing with sort of let me draw out at least a little bit of pathways What if I'm dealing with sort of a different type of game? Maybe I'm dealing with a cat This is my drawing of a cat be happy I'm at least trying I want a cat that is chasing a mouse. So here is sort of my mouse All right. Well again, oh, you know the a star calculations are kicking in and firing off You know the g's here would be a one and then I have to do the one two three so g again One h if I did Manhattan. I just that's the one I picked off the top of my head One two three it would take me a three step There's another route that I'd have to do it more to my point is let's say arbitrarily I did make this move. This is where I ended up after that first action Well, it's a mouse right and if we think about a mouse seeing a cat Come towards it It probably is going to try and run away and what I mean by that is my goal sort of again this goal May be changing right the rat Or mouse may move down a pathway And oh, well, you know, suddenly, uh, I have to recalculate where I am because I'm no longer here My goal is no longer here. I'm going to have to take from where I'm at and Do a new calculation to potentially a new goal So when we think about the properties again pulling out those terminologies, what we're dealing with is Is it complete? Yes, we are going to be able to find a solution if a solution exists And then we look at this idea of optimality. Okay. Well, when we think about optimal, is it going to give me the optimal solution? What we instead change for instead of optimal because we're going to learn that that's a really hard, uh, solution or a term to kind of chase after What we're going to see is that it is admissible It will get me a solution that is better than most solutions or Then a lot of the other solutions. So, uh, from a tree search perspective again better then some other searches May not be the optimal one, but it, uh, again, may be better may not be again That's we'll get to that and then this idea of consistent as a graph search If I'm looking at it from a graphs perspective versus a tree structure. What we're dealing with here is we'll get solutions on par And they're going to give us something that's going to be on par with some of the other solutions But again, it's going to get us that solution and more specifically That's where we introduce the idea of the spacetime complexity part, right? This is the uh slightly more important one depending on what we're dealing with And so again, well, how much time is it going to take? Well, it sort of depends and May take us there. I'll get to that in a second It will take us roughly the number of nodes With f of n smaller than the cost of the optimal path again if we looked at sort of these, uh F's right there was eventually some calculation. Uh, in our case of Raleigh to Seattle, where's The Seattle there That f right there was 2988. That was the total cost. That's the f score of taking this pathway So what we're dealing with is then if we're looking at it from a time complexity Again, roughly the number of nodes smaller than the overall cost it took us More than four steps But it's again, how many nodes had a cheaper than not a 2988 route? And again, I'm not gonna walk through it. But again, there were a few that had a cheaper than 988 route 2988 route And then same with uh, how much memory is it needing? Well, again, same idea Let me make sure that I got my Drawing tool on It's gonna again take just as many more nodes that happen to be cheaper Then my optimal pathway so as I sort of You know Danced in and I'll at least sort of accept and that I I can show it How do I build it right? I've shown you the algorithm. You can work through it. Great I need to build this for Uh class, right This is sort of my recommendation and this link will be in the the description down below I really like sort of this uh description of how a star sort of operates From red blob games.com What we sort of see here is Very very much like python. It's python, but not at the same time. It's not all python But that first idea you can see is that we're dealing with building out a new term this idea of a frontier again what To consider These are things that are when we again think about the priority queue Again Kansas City to Salt Lake City It was on the table to be considered it, right? It's in the queue We've happened to found our path, but what happened or our goal? But what happens if that path didn't exist? Well, I have other things that I could be considering in my frontier So again, what are we doing at that starting point? Well again just to get there One of the things that is lovely at least about uh in sea state is in 316 data structures You had to build your priority queue Congratulations. You built it in data structures. You understand the heap and bubbling up and Bubbling down none of that you are more than welcome at least for our iteration When we do our path finding uh Assignment you're more than welcome to use java.util.priority queue The big idea though that I will sort of address is sort of this e That e in our case is some element again. This is a generic so i'm doing a little bit of refresher to People who are probably learning this for the first time again. I have some generic variable in java That i'm assigning to priority queue. What is that going to be? Well, it depends on what you're working with it could be a node It could be in our case a position or a tile it all depends One of the things to kind of point out here is you know, depending on what you're Using as a language in our case. We're working off of java. Guess what this dot put Is in the command to add something to the priority queue I'm going to leave that to you getting a little more experience about reading documentation Which is an important task, but again, what is the command to? add to a priority queue Then specifically that idea again. I was talking about this idea of what start is At least a little bit of a note for those of you in our AI course or 411 My big recommendation you should probably create some kind of node that extends Or implements I can't remember off the top of my head comparable The idea here is again when we think about different types of nodes, right? What's going to make sort of when I add You know going To salt charlotte from rdu I'm going to need to compare that to Going from atlanta Are going to atlanta from rdu Well, what is this? I need to build this Just this mostly just hints Either way the next little bit is that you're wanting to build some dictionaries or From the java perspective. They're called maps The big idea here is that these are going to be working off of some reference points specifically this came from If you remember when I was drawing out my different sort of tiles I was sort of always Using this idea of oh, well, you know, seattle came from oh hair. Oh hair Came from charlotte charlotte Came from rdu Once again, I need some way to make that reference. I could programmatically build it and make nodes have a parent Variable and I store it there or or just Throwing this out there. I could have a dictionary where this came from on say charlotte Could equal rdu and once again, what do I mean by rdu? It's the node that represents that or the tile position again Depending on your assignment Well, again, that's telling me. Oh, I happened to know Where something came from and I also am going to happen to know the cost to get to charlotte Again because I happen to know. Oh, it was a Just off the top of my head because I just saw it. I remember it was 167 miles. So the cost to get to charlotte would be That okay. Well walking through the algorithm or the pseudocode then shameless promotion if you are unfamiliar with maps, uh, there's a Handsome little little devil that's uh made a video you can check out right now, uh on how to use a map But moving on so again, we're in the priority queue and so again while the queue frontier dot I'm just drawing out some Little bit of java. So while the frontier is not empty or python The first thing we're doing is we're grabbing again that root node. What was the priority? What's has the highest priority right now once again? May not be good. So you got to check your documentation Either way with the current I ask a simple question first Is that current the goal so when we were at seattle? Yes, great But what happens when we moved to charlotte? Okay. Well, that was not the goal So we continue checking out. What are the neighbors? Of charlotte and this again is now checking all the possible pathways from this And what do we do? Well, the first thing we're going to do is we're going to effectively cost or figure out our g new cost is referring to again How much did it take to get here? Plus just What's this next step again when it was uh, charlotte that was again only just 167 But remember we also did charlotte to o'hair or d And that turned out to be 167 plus. I believe 7 15 That's what we're dealing with here again. This is the 167. So that's the 167 That's the 7 15 Either way, we've just calculated out g now. What do we do? I guess I skipped let me pull this one then now that I have that Well, okay. I see that that is not in there. So I haven't considered this path This is a little bit of dykstra's algorithm in the a star Going on here and this happens to be the Cheapest this new cost is going to be cheaper Then before so again, we're sort of storing that for later usage and then notice specifically What's the h? And they're sort of throwing that as it's again, whatever function you want it to be Is it going to be the manhattan distance? Is it going to be straight line? Are you going to do, you know the distance between two points? And so literally a distance formula Or some other heuristic that I'm Not even thinking of at this time. But again, you can see so this idea of priority That's a that's a kin to f And so when we then think about new cost just like we said before new cost is a kin to g And then as you can sort of see from that last little bit there heuristic And I'll just do that heuristic is our h We have calculated out our f and so what so what do we do? Well, then we take That next potential step and we add it to the priority queue with its f And then you can see oh where happen we happen to Acknowledge oh from this location. I came from wherever I was so again when we think about uh o r d so o hair came from o r d And again our current If we're thinking about this again just working off of our example was clt We're just storing that again for later use because at the end of the day once we've found all this and we break out Of the queue. What do we have to do? We have to figure out How do I get back or how do I make my first step notice? None of this is telling me what the first step is That's where i'm going to have to traverse these different steps. So again where did I get How did I get to seattle? Well, I went to o r d So, oh, well, how did I get to o r d? I went to charlotte, how did I get to charlotte? Oh, I went from r du. Hey, wait a minute r du was my starting point I've no suddenly which move I have to do next ah a star