Question: 1. (30 points) In this exercise we are going to modify the DFS procedure so that it returns for the given undirected graph G, the
1. (30 points) In this exercise we are going to modify the DFS procedure so that it returns for the given undirected graph G, the connected components of that graph. To do this we will modify the DFS procedure so that it computes the connected components as follows:
It maintains a counter i, initially set in 1, that counts how many connected components we found so far On each vertex v G.V it maintains an attribute component indicating to which connected component number v belong to. That is, when DFS terminates, v.component indicates the component number 1, 2, . . . i that v belongs to. Answer the following questions:
(a) (10 points) Write the pseudocode for this slightly modified version of the DFS algorithm
(b) (10 points) Explain why your algorithm is correct
(c) (10 points) Explain its running time.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
