深度优先搜索 (depth-first search,DFS)

深度优先搜索 (depth-first search,DFS)

1. 深度优先搜索 (depth-first search,DFS)

depth-first search,DFS:深度优先搜索
breadth-first search,BFS:广度优先搜索

Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking.
深度优先搜索 (DFS) 是用于遍历或搜索树或图形数据结构的算法。该算法从根节点开始 (在图的情况下,选择任意节点作为根节点),并在回溯之前尽可能沿着每个分支进行探索。

深度优先搜索 (depth-first search,DFS) 是一种用于遍历或搜索树或图的算法。沿着树的深度遍历树的节点,尽可能深的搜索树的分支。当节点 v 的所在边都己被探寻过,搜索将回溯到发现节点 v 的那条边的起始节点。这一过程一直进行到已发现从源节点可达的所有节点为止。如果还存在未被发现的节点,则选择其中一个作为源节点并重复以上过程,整个进程反复进行直到所有节点都被访问为止。深度优先搜索 (depth-first search,DFS) 属于盲目搜索。

深度优先搜索是图论中的经典算法,利用深度优先搜索算法可以产生目标图的相应拓扑排序表,利用拓扑排序表可以方便的解决很多相关的图论问题,如最大路径问题等等。

在这里插入图片描述

在这里插入图片描述

发布了510 篇原创文章 · 获赞 1825 · 访问量 110万+

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/104887471