> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/letcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/letcode/2.algorithm/26guang-du-you-xian-sou-xun-breadth-first-search.md).

# 2.6.2.6.廣度優先搜尋 (Breadth-first Search)

## 1.Introduction (參考自: <http://simonsays-tw.com/web/DFS-BFS/BreadthFirstSearch.html>)

* 是一種圖形(graph)搜索演算法
* 從圖的某一節點(vertex, node)開始走訪, 接著走訪此一節點所有相鄰且未拜訪過的節點, 由走訪過的節點繼續進行先廣後深的搜尋
* 以樹(tree)來說即把同一深度(level)的節點走訪完, 再繼續向下一個深度搜尋, 直到找到目的節點或遍尋全部節點
* 廣度優先搜尋法屬於盲目搜索(uninformed search)是利用佇列(Queue)來處理

![](https://1568020728-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4M0G8JEXoorTQqbFzd%2F-M4M0IPqKD21qkycuQ-D%2F-M4M0LPMAevwQCxuq-at%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-04-30%20%E4%B8%8A%E5%8D%8810.24.22.png?generation=1586302917736934\&alt=media)

## 2.例子

* 請參考[3.3.1.Binary Tree traversal: Level-Order Traversal](https://jenhsuan.gitbooks.io/letcode/content/3data-structure/33binary-tree/331binary-tree-traversal.html)
