Question: 2. You are given the same graphs again. (a) (5 points) Say we perform a Depth First Search (DFS), starting with vertex A, on the
2. You are given the same graphs again. (a) (5 points) Say we perform a Depth First Search (DFS), starting with vertex A, on the undirected graph (above left) and count the vertices as we encounter them as described below. Finish filling out the count and previous arrays as determined by our DFS. Assume G. adjacents () return vertices adjacent to v in alphabeticumeric order DFSCG, ) previous visited for v in G.V A 0 8-1 C#2 visited[v] false B-1 C#2 visited[s]-true previous[s) 1 pushCs) whi le stack not enpty B-1 D-3 F-5 v-pop count Ev]- for win G.adjacents(v) if Civisitedn) ( G#6 visited[m]. true; H#7 H-7 previous[n- pushCn): (b) (5 points) Repeat (a) using the directed graph on the right above. DFSCG, s) visited for v in G.V A#01-1 1 visited[]-false; 8-1 C-2 Bel visited[s] true; previous[s pushCs): whi le stack not empty D-3 F 5 F 5 F 5 count [v] - forwin G.adjacents G-6 H-7 H-7 visited true; previous[
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
