What is breadth-first search useful for?

前端 未结 10 1316
野趣味
野趣味 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 17:02

    When you want to reach a node by traversing as few edges as possible, i.e. when you want to find the shortest path in an unweighted graph.

    Also the space complexity of a depth first search can be higher than that of a breadth first search when e.g. each node has only one child node, i.e. when the graph is deep but not very broad.

提交回复
热议问题