So far, what you’ve created is a modified Dijkstra’s algorithm that has a target and returns the path to that target.

To make this algorithm truly a star A*, you’ll need to add a heuristic that estimates the distance from a given vertex to the target.

By doing this, the algorithm is able to efficiently and accurately predict whether or not it is heading in the best possible direction.



Scroll down to the bottom of the file and uncomment the code. Run it to see how Dijkstra’s path-finds in all directions, while A* uses its heuristic to focus the search in a particular direction.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?