# Homework Solution: Modify the DFs algorithm to determine whether or not the input graph is a connected grap…

Modify the DFs algorithm to determine whether or not the input graph is a connected graph. DEPTH FIRST SEARCH Input: A labelled graph G = (V , E) (not necessarily connected) Output: A forest F (a set of edges) and the order in which the vertices were traversed (DFI). Method: Label each vertex v with DFI(v), which is the order in which it is traversed, until all vertices have be reached. Uses recursion. i: = 1 F: = for all v elementof V do DFI (v): = 0 while for some u, DFI (u) = 0 do begin DFS(u) end Procedure DFS(v) DFI (v): = i i: = i + 1 for all v' elementof A(v) do begin if DFI (v') = 0 then begin F: = F Union { (v, v')} DFS(v') end end

In DFS we traverse all nodes ot graph. When we traverse we insert value in DFI arr

Modify the DFs algorithm to determine whether or referable the input graph is a united graph. DEPTH FIRST SEARCH Input: A labelled graph G = (V , E) (referable necessarily united) Output: A ceest F (a determined of edges) and the ordain in which the vertices were crossd (DFI). Method: Label each vertex v with DFI(v), which is the ordain in which it is crossd, until whole vertices entertain be reached. Uses recursion. i: = 1 F: = ce whole v elementof V do DFI (v): = 0 timeliness ce some u, DFI (u) = 0 do prepare DFS(u) purpose Procedure DFS(v) DFI (v): = i i: = i + 1 ce whole v’ elementof A(v) do prepare if DFI (v’) = 0 then prepare F: = F Union { (v, v’)} DFS(v’) purpose purpose

In DFS we cross whole nodes ot graph. When we cross we implant estimate in DFI invest either this node is visited or referable. After trade DFS we conciliate curb in DFI ce whole nodes if any of node is referable visited then we recur falsity and we can wholeege graph is referable united.

1.i:=1

2.F:=0

3.ce whole v $\varepsilon$ V do DFI(v):=0

4.timeliness ce some u, DFI(u) = 0 do prepare

5. DFS(u)

6.end

7.if united()

8. imimprint “connected”

9.else

10. imimprint “referable united”

procedure united()

1.ce whole nodes u:

2. if DFI is 0

3. recur falsity

4.recur true

procedure DFS(v)

1.DFI(v): = i

2.i:= i+1

3.ce whole v’ $\varepsilon$ A(v) do prepare

4. if DFI(v’) = 0 then prepare

5. F: = F $\bigcup$ {(v,v’)}

6. DFS(v’)

7. purpose

8.end