Question: Complete example 3 of the depth first search/traversal algorithm. Depth First Search/Traversal (DFS) Algorithm: Set starting vertex of the graph as visited and push it
Complete example 3 of the depth first search/traversal algorithm.


Depth First Search/Traversal (DFS) Algorithm: Set starting vertex of the graph as visited and push it onto the stack While the stack is not empty Peek at top vertex on the stack If there is an unvisited connection for that vertex Mark that unvisited connection as visited and push that vertex onto the stack se Pop the top vertex off the stack Example 1-use Gas starting vertex: Action Visited Vertices Unvisited Vertices B. C, D. E, F Stack Begin with vertex G Push G (G Peek at G (top of stack) Push B (G, B) and visit connection if A, C, D, E,F G, B resent otherwise pop Peek at B (top of stack)Push A (G, B, A) and visit connection if C, D, E, F G, B, A resent otherwise Peek at A and visit/pop Push D (G, B, A, D) as needed Peek at D and visit/pop Push C (G, B, A, D, C) as needed Peek at Cand visit/pop Push F (G, B, A, D, C, F) E as needed Peek at F and visit/pop Push E (G, B, A, D, C, F, E) as needed Peek at E and visit/pop Pop E (G, B, A, D, C, F) as needed Peek at F and visit/po Peek at C and visit/po Peek at D and visit/po Peek at A and visit/ Peek at B and visi Peek at G and visit C, E, F G, B, A, D G, B, A, D, C G, B, A, D, C, F G, B, A, D, C, F, E G, B, A, D, C, F, E Pop F (G, B, A, D, C Pop C (G, B, A, D Pop D (G, B, A Pop A (G, B) Pop B (G Pop G (Em G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E Depth First Search/Traversal (DFS) Algorithm: Set starting vertex of the graph as visited and push it onto the stack While the stack is not empty Peek at top vertex on the stack If there is an unvisited connection for that vertex Mark that unvisited connection as visited and push that vertex onto the stack se Pop the top vertex off the stack Example 1-use Gas starting vertex: Action Visited Vertices Unvisited Vertices B. C, D. E, F Stack Begin with vertex G Push G (G Peek at G (top of stack) Push B (G, B) and visit connection if A, C, D, E,F G, B resent otherwise pop Peek at B (top of stack)Push A (G, B, A) and visit connection if C, D, E, F G, B, A resent otherwise Peek at A and visit/pop Push D (G, B, A, D) as needed Peek at D and visit/pop Push C (G, B, A, D, C) as needed Peek at Cand visit/pop Push F (G, B, A, D, C, F) E as needed Peek at F and visit/pop Push E (G, B, A, D, C, F, E) as needed Peek at E and visit/pop Pop E (G, B, A, D, C, F) as needed Peek at F and visit/po Peek at C and visit/po Peek at D and visit/po Peek at A and visit/ Peek at B and visi Peek at G and visit C, E, F G, B, A, D G, B, A, D, C G, B, A, D, C, F G, B, A, D, C, F, E G, B, A, D, C, F, E Pop F (G, B, A, D, C Pop C (G, B, A, D Pop D (G, B, A Pop A (G, B) Pop B (G Pop G (Em G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E G, B, A, D, C, F, E
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
