Download presentation
Presentation is loading. Please wait.
1
Instructor : Prof. Jyh-Shing Roger Jang
Depth First Search Instructor : Prof. Jyh-Shing Roger Jang Designer:Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “ .
2
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ 1 node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 1 1 1 1 2 1 1 1 3 4 5 6 1 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v Find the node which is not visited
3
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 2 2 2 1 2 2 2 2 3 4 5 6 1 2 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 Find the node which is not visited
4
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 3 3 3 1 visited 2 3 3 3 3 4 5 6 1 2 3 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 Find the node which is not visited
5
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 4 4 4 1 2 4 4 4 3 visited 4 5 6 1 2 3 4 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 7 Find the node which is not visited
6
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 5 5 5 1 2 visited 5 5 5 3 4 5 6 1 2 3 4 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list visited Markup the node which already visited Print the value of v 1 3 7 4 Find the node which is not visited
7
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 1 2 4 4 3 4 5 6 1 2 3 4 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 7 4 Find the node which is not visited
8
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 5 5 5 1 2 5 5 5 3 4 5 6 1 2 3 4 5 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 7 4 5 Find the node which is not visited
9
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } visited 6 6 6 1 2 6 6 6 3 4 5 6 visited 1 2 3 4 5 6 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 7 4 5 2 Find the node which is not visited
10
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 7 7 7 1 2 visited 7 7 7 3 4 5 6 visited 1 2 3 4 5 6 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list visited Markup the node which already visited Print the value of v 1 3 7 4 5 2 6 Find the node which is not visited
11
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 1 2 5 4 6 4 5 3 4 5 6 visited 1 2 3 4 5 6 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list visited Markup the node which already visited Print the value of v 1 3 7 4 5 2 6 Find the node which is not visited
12
Depth First Search 1 2 3 4 5 6 7 void dfs(int v){ node_pointer w;
void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v); for(w = graph[v]; w; w = w->link) if(!visited[w->vertex]) dfs(w->vertex); } 1 2 visited 1 3 2 2 1 3 4 5 6 visited 1 2 3 Input the first vertex into dfs 7 Declare variable to put the graph[v] of Adj-list Markup the node which already visited Print the value of v 1 3 7 4 5 2 6 Find the node which is not visited
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.