190 likes | 265 Views
Explore the basic idea of BFS and A* algorithm. BFS branches out to all surrounding nodes without direction discrimination. Best-First Search branches out to the closest nodes using heuristics. A* algorithm improves Best-First Search by assigning node weights based on cost and estimated distances. Learn about Manhattan Distance as an heuristic and see A* algorithm implementation examples. Compare BFS and A* algorithms along with their special cases like Dijkstra's Algorithm.
E N D
Basic Idea BFS brances out to all surrounding nodes No discrimination based on direction of target node
BFS example S E
BFS example S E
BFS example S E
BFS example S E
BFS example S Large area needlessly explored E
Alternatives Best-First Search: Branch out to nodes which intuitively seem to be the closest to the destination Use heuristics to estimate distances to destination node Greedy algorithm However, a better solution exists
A* algorithm A* is an improvement over Best-First Search Nodes are given weights based on: Cost to reach the node Estimated cost to reach the end node
Manhattan Distance Manhattan distance - sum of the absolute distances between coordinates M(x1,y1,x2,y2) = |x1-x2| + |y1-y2| Reflection of distance between points if travel only parallel to axes
Implementation of A* Using Manhattan distance as an heuristic to estimate distance to end point w(x,y) = c(x,y) + M(x,y,xE,yE) Item in priority queue with lowest weight popped off Surrounding nodes added with calculated weights
A* example S E
A* example S 9 7 E
A* example S 9 7 9 7 E
A* example S 9 7 9 7 7 E
A* example S 9 7 9 7 7 7 7 E
A* example 11 S 9 11 11 9 7 9 11 9 7 7 7 9 7 7 9 9 E
Comparison: BFS vs A* BFS A* S S E E
Special cases of A* Dijkstra's Algorithm is a case of A* with the weighting based solely on cost: w(x,y) = c(x,y) Breadth-First Search is just A* with all nodes have a weight of 0: w(x,y) = 0