What is breadth-first search useful for?

前端 未结 10 1229
野趣味
野趣味 2020-12-14 16:43

Usually when I\'ve had to walk a graph, I\'ve always used depth-first search because of the lower space complexity. I\'ve honestly never seen a situation that calls for a b

10条回答
  •  醉梦人生
    2020-12-14 16:59

    When does it make sense to use a breadth-first search?

    For example, when you need to find the shortest path in a graph - DFS just can't do that. There are some other applications, but, in general, DFS and BFS are the same algorithm working on different data structures (BFS uses queue and DFS works with stack).

提交回复
热议问题