There are two ways to traverse a graph:
1 Depth First
The algorithm is similar to the first root traversal of a tree;
2 Breadth First
The algorithm is similar to the hierarchical traversal of trees;
Case:
650) this.width=650; "src=" http://img.blog.csdn.net/20150719154004657 "alt=" here write a picture describing "title=" "/>
Depth-First traversal order: V1–V2–V4–V8–V5–V3–V6–V7
Breadth-First traversal order: V1–V2–V3–V4–V5–V6–V7–V8
3 precautions
1) A graph, it's depth first and breadth first is not unique, can have multiple!
2) The general situation is to give the adjacency table or adjacency matrix depth first and breadth first, at this time, depth first and breadth first is unique, because when your storage structure fixed, depth first and breadth first also fixed!
This article is from the "Sanghaidan blog column" blog, please be sure to keep this source http://10602803.blog.51cto.com/10592803/1683047
Graph traversal method (depth first and breadth first algorithm)