1 / 12

Depth First Search

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 “. Depth First Search. void dfs(int v){ node_pointer w; visited[v] = TURE; printf(“%5d”, v);

mickelsen
Download Presentation

Depth First Search

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 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); } 0 1 1 1 1 2 1 1 1 3 4 5 6 1 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 Find the node which is not visited

  3. Depth First Search 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); } 0 2 2 2 1 2 2 2 2 3 4 5 6 1 2 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 Find the node which is not visited

  4. Depth First Search 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); } 0 3 3 3 visited 1 2 3 3 3 3 4 5 6 1 2 3 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 Find the node which is not visited

  5. Depth First Search 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); } 0 4 4 4 visited 1 2 4 4 4 3 4 5 6 1 2 3 4 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 Find the node which is not visited

  6. Depth First Search 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); } 0 5 5 5 visited visited 1 2 5 5 5 3 4 5 6 1 2 3 4 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 Find the node which is not visited

  7. Depth First Search 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); } 0 1 2 4 4 3 4 5 6 1 2 3 4 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 Find the node which is not visited

  8. Depth First Search 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); } 0 5 5 5 1 2 5 5 5 3 4 5 6 1 2 3 4 5 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 5 Find the node which is not visited

  9. Depth First Search 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); } 0 6 6 6 visited visited 1 2 6 6 6 3 4 5 6 1 2 3 4 5 6 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 5 2 Find the node which is not visited

  10. Depth First Search 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); } 0 7 7 7 visited visited visited 1 2 7 7 7 3 4 5 6 1 2 3 4 5 6 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 5 2 6 Find the node which is not visited

  11. Depth First Search 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); } 0 visited visited 1 2 6 5 4 5 4 3 4 5 6 1 2 3 4 5 6 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 5 2 6 Find the node which is not visited

  12. Depth First Search 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); } 0 visited visited 1 2 1 2 3 2 1 3 4 5 6 1 2 3 Input the first vertex into dfs Declare variable to put the graph[v] of Adj-list 7 Markup the node which already visited Print the value of v 0 1 3 7 4 5 2 6 Find the node which is not visited

More Related