4.2 - Graph Traversal
DFS (Undirected Graph)
void DFS(int graph[NUM_NODES][NUM_NODES], int *visit, int start){
//adjacency matrix(Graph以相鄰矩陣表示)
printf("%d ", start);
visit[start] = 1;
for (int i = 0; i<NUM_NODES; i++){
if (graph[start][i] == 1 && visit[i] == 0) //未曾拜訪過且是相鄰頂點
DFS(graph, visit, i);
}
}BFS (Undirected Graph)
BFS (Undirected Graph)(Algo)
DFS (Directed Graph)(Algo)
應用
Is the undirected graph connected?
Is there cycles in the graph?
Last updated


