深度優先搜索 (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) 屬於盲目搜索。

深度優先搜索是圖論中的經典算法,利用深度優先搜索算法可以產生目標圖的相應拓撲排序表,利用拓撲排序表可以方便的解決很多相關的圖論問題,如最大路徑問題等等。

在這裏插入圖片描述

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章