7.5 graph Traversal
Graph traversal is similar to tree traversal. A certain vertex accesses the rest of the vertices, and each vertex is accessed only once. This process is called graph traversal. Divided into depth-first traversal and breadth-first Traversal
7.5.1 deep priority Traversal
Depth-first traversal Depth_First_Search), also known as depth-first search, or DFS for short.
Deep priority search is actually a recursive process. It is like traversing a tree in the forward order. A vertex V is used to access this vertex, then, the depth traversal graph is prioritized from the inaccessible neighboring contacts of V until all vertices with the same path as V are accessed. If there are still unaccessed vertices in the graph, select an unaccessed vertex in the graph as the starting point and repeat the above process until all vertices in the graph are accessed.
The Code is as follows:
650) this. width = 650; "title =" QQ20130909175900.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/20134a563-0.jpg "/>
For the structure of the adjacent table, the Code is as follows:
650) this. width = 650; "title =" QQ20130909180148.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/2013491A0-1.jpg "/>
7.5.2 breadth-first Traversal
1. For a vertex V0, first access V0.
2. Access the neighboring nodes that have not been accessed in V0 in sequence.
3. Start from these neighboring contacts and access each of their unvisited neighboring contacts in sequence.
This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1293328