[algorithm] When is it practical to use Depth-First Search (DFS) vs Breadth-First Search (BFS)?

This is a good example to demonstrate that BFS is better than DFS in certain case. https://leetcode.com/problems/01-matrix/

When correctly implemented, both solutions should visit cells that have farther distance than the current cell +1. But DFS is inefficient and repeatedly visited the same cell resulting O(n*n) complexity.

For example,

1,1,1,1,1,1,1,1, 
1,1,1,1,1,1,1,1, 
1,1,1,1,1,1,1,1, 
0,0,0,0,0,0,0,0,

Examples related to algorithm

How can I tell if an algorithm is efficient? Find the smallest positive integer that does not occur in a given sequence Efficiently getting all divisors of a given number Peak signal detection in realtime timeseries data What is the optimal algorithm for the game 2048? How can I sort a std::map first by value, then by key? Finding square root without using sqrt function? Fastest way to flatten / un-flatten nested JSON objects Mergesort with Python Find common substring between two strings

Examples related to graph-algorithm

Find all paths between two graph nodes Negative weights using Dijkstra's Algorithm When is it practical to use Depth-First Search (DFS) vs Breadth-First Search (BFS)? Finding all cycles in a directed graph

Examples related to graph-theory

Why is the time complexity of both DFS and BFS O( V + E ) Find all paths between two graph nodes When is it practical to use Depth-First Search (DFS) vs Breadth-First Search (BFS)? Difference between hamiltonian path and euler path How to draw a graph in LaTeX? When should I use Kruskal as opposed to Prim (and vice versa)? Find the paths between two given nodes? Finding all cycles in a directed graph Cycles in an Undirected Graph Best algorithm for detecting cycles in a directed graph When is it practical to use Depth-First Search (DFS) vs Breadth-First Search (BFS)? Breadth First Vs Depth First Why is the time complexity of both DFS and BFS O( V + E ) Find all paths between two graph nodes How to trace the path in a Breadth-First Search? How does a Breadth-First Search work when looking for Shortest Path? How do implement a breadth first traversal? When is it practical to use Depth-First Search (DFS) vs Breadth-First Search (BFS)? Performing Breadth First Search recursively Breadth First Vs Depth First