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 A labelled graph G = (V , E) (not necessarily connected) were traversed (DFI). is traversed, until all vertices have be reached. Uses recursion Input Output A forest F (a set of edges) and the order in which the vertices Method: Label each vertex v with DFI(v), which is the order in which it 3. for all v eV do DFI (v) := 0 4. while for some u, DFI (u)- 0 do begiin 5.DFS(u) 6. en Procedure DFS(v) 1. DFI (v):-i 3. for all ve A(v) do begin 4.if DFI (V) -0 then begin DFS(v) 7. end 8. end
    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

    Expert Answer

     
    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 A labelled graph G = (V , E) (referable necessarily united) were crossd (DFI). is crossd, until whole vertices entertain be reached. Uses recursion Input Output A ceest F (a determined of edges) and the ordain in which the vertices Method: Label each vertex v with DFI(v), which is the ordain in which it 3. ce whole v eV do DFI (v) := 0 4. timeliness ce some u, DFI (u)- 0 do begiin 5.DFS(u) 6. en Procedure DFS(v) 1. DFI (v):-i 3. ce whole ve A(v) do prepare 4.if DFI (V) -0 then prepare DFS(v) 7. purpose 8. purpose

    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

    Expert Reply

     

    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