retagged by
2,521 views

1 Answer

14 votes
14 votes

starts with A, Now you have choice of B and D, according to Tie break rule B is choosen

Now you are at B, you have choice of E only,

Now you are at E, you have choice of C and G, according to Tie break rule C is choosen

Now you are at C, you have choice of A and G, but note that A already visited, therefore you have choice of G only.

Now you are at G, you can't go ===> control return to C

Now you are at C, you can't go (due to all adjacent vertices completed ) ===> control return to E

Now you are at E, you can't go (due to all adjacent vertices completed ) ===> control return to B

Now you are at B, you can't go (due to all adjacent vertices completed ) ===> control return to A

Now you are at A, you have choice of D only,

Now you are at D, you have choice of F only,

Now you are at F, you can't go (due to all adjacent vertices completed ) ===> control return to D

Now you are at D, you can't go (due to all adjacent vertices completed ) ===> control return to A

Now you are at F, you can't go (due to all adjacent vertices completed ) ===> DFS travel over.

Now your DFS tree look like as

Note that there is no difference between right and left ( As we did in Binary trees )

Now take every edge of Graph G

(A,B) ===> part of DFS tree ===> it is Tree Edge

(A,D) ===> part of DFS tree ===> it is Tree Edge

(B,E) ===> part of DFS tree ===> it is Tree Edge

(E,C) ===> part of DFS tree ===> it is Tree Edge

(E,G) ===> E is a Ancestor of G ===> it is Forward Edge

(C,A) ===> C is a Descendent of A ===> it is Backward Edge

(C,G) ===> part of DFS tree ===> it is Tree Edge

(D,F) ===> part of DFS tree ===> it is Tree Edge

(F,C) ===> F is neither Ancestor nor Descendent of C ===> it is Cross Edge

(F,G) ===> F is neither Ancestor nor Descendent of G ===> it is Cross Edge

totally, 6 Tree Edges ( due to 7 vertices ) + 1 Forward Edge + 1 Backward Edge + 2 Cross Edges exist in this graph G

 

For Directed Graph:-

total edges = Tree edges + Front Edges + Back Edges + Cross Edges

 

For Undirected Graph:-

total edges = Tree edges + Front Edges ( or Back Edges )

https://gateoverflow.in/279686/data-structure-doubt?show=279829#c279829

edited by

Related questions

0 votes
0 votes
1 answer
4
vaishali jhalani asked Nov 4, 2016
468 views
Can we use DFS to detect the negetive weight cycle in a directed graph?