Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what cases would BFS and DFS be more efficient than A* search algorithm?

I've tested A* search against Breadth First Searching (BFS) and Depth First Searching (DFS) and I find that fewer nodes are being expanded with A*.

I understand that A* expands paths that are already less expensive by using the heuristic and edge cost function.

In what cases would BFS and DFS be more efficient as compared to A* search algorithm?

like image 351
Marjan Avatar asked Apr 19 '18 04:04

Marjan


People also ask

When would DFS be A better choice than A * Search?

A depth-first search may outperform A* and BFS if the goal is on the first branch. In this demo you can place the goal at different states in the tree to see what happens. There are other constant factors to consider. DFS only needs a single copy of a state, while A* keeps many states on the OPEN/CLOSED lists.

WHY A * algorithm is better than BFS?

The benefit of A* is that it normally expands far fewer nodes than BFS, but if that isn't the case, BFS will be faster. That can occur if the heuristic used is poor, or if the graph is very sparse or small, or if the heuristic fails for a given graph. BFS is particularly useful for unweighted graphs.

Is BFS or DFS more efficient?

DFS is faster than BFS. Time Complexity of BFS = O(V+E) where V is vertices and E is edges. Time Complexity of DFS is also O(V+E) where V is vertices and E is edges.

Why DFS is preferred over BFS for AI problems?

BFS can be used to find a single source shortest path in an unweighted graph because, in BFS, we reach a vertex with a minimum number of edges from a source vertex. In DFS, we might traverse through more edges to reach a destination vertex from a source.


2 Answers

BFS uses a queue while A* uses a priority queue. In general, queues are much faster than priority queues (eg. Dequeue() is O(1) vs O(log n)). The advantage of A* is that it normally expands far fewer nodes than BFS, but if that isn't the case, BFS will be faster. That can happen if the heuristic used is poor, or if the graph is very sparse or small, or if the heuristic fails for a given graph.

Keep in mind that BFS is only useful for unweighted graphs. If the graph is weighted, you need to use BFS's older brother, Dijkstra's Algorithm. This algorithm uses a priority queue, and as such should almost never be faster than A*, except in cases where the heuristic fails.

like image 199
BlueRaja - Danny Pflughoeft Avatar answered Oct 20 '22 20:10

BlueRaja - Danny Pflughoeft


A breadth-first search may outperform A* when the heuristic is inconsistent. (An inconsistent heuristic doesn't obey the triangle inequality. A consistent heuristic never changes more than the edge cost from one state to the next.)

With an inconsistent heuristic A* may expand N states up to 2^N times. The example of where this occurs can be found online. Step through the example if you want to understand what happens. BFS will only expand each state at most once. Note that this can be partially fixed by algorithm B (N states expanded at most N^2 times), but this is still a large overhead. The recent IBEX algorithm has much better worst-case guarantees - N log C*, where C* is the optimal solution cost.

A depth-first search may outperform A* and BFS if the goal is on the first branch. In this demo you can place the goal at different states in the tree to see what happens.

There are other constant factors to consider. DFS only needs a single copy of a state, while A* keeps many states on the OPEN/CLOSED lists. But, in these cases IDA* should be used instead.

Note that theoretically speaking, in unidirectional search with a consistent heuristic, A* does the fewest number of necessary expansions required to prove that the solution is optimal.

like image 31
Nathan S. Avatar answered Oct 20 '22 22:10

Nathan S.