From the course: Python Data Structures and Algorithms

Solution: Trace the path of an A* search - Python Tutorial

From the course: Python Data Structures and Algorithms

Solution: Trace the path of an A* search

(upbeat music) - [Instructor] And here's a solution for the A-star challenge. So the path produced is zero zero zero one one one one two two two three two three three. Now note, this is the same path as for BFS. And I may have given away that information a little bit too early and you might have known that already and just looked to your previous answer. But the idea of this challenge is of course to work through the algorithm so I hope you did do that. This the same because both BFS and A-star guarantee a shortest path and that's with certain conditions on the heuristic that's used. But generally speaking, it's going to be the shortest path for both. The difference is that A-star gets there with far fewer steps. It's a much better or more efficient algorithm. Now, as an additional exercise, if you'd like you can check this result by going into your project, going into mazes. You'll see, we have the challenge maze there. That's exactly the same maze as on the challenge slide. And you can use that maze in your A-star. So you can open up your A-star. And then you can write some code. You can make a function call passing in that challenge maze. So it's going to be very similar to, for example, line 53. And you can just print the result of the function code if you'd like or you can do an assert statement. But basically you've got the ability now to use all of this code that you've written. And we've given you mazes so you can really just do some of your own exploration with it, make sure you understand how it's working, maybe on a bigger maze if you'd like. Choice is yours how you work with this project now. Anyway, the main point being this was the path and that's the end of that challenge.

Contents