in Algorithms retagged by
27,221 views
47 votes
47 votes

Let $G$ be a simple undirected graph. Let $T_D$ be a depth first search tree of $G$. Let $T_B$ be a breadth first search tree of $G$. Consider the following statements.

  1. No edge of $G$ is a cross edge with respect to $T_D$. (A cross edge in $G$ is between two nodes neither of which is an ancestor of the other in $T_D$).
  2. For every edge $(u, v)$ of $G$, if $u$ is at depth $i$ and $v$ is at depth $j$ in $T_B$, then $\mid i-j \mid =1$.

Which of the statements above must necessarily be true?

  1. I only
  2. II only
  3. Both I and II
  4. Neither I nor II
in Algorithms retagged by
by
27.2k views

4 Comments

reshown by

@ can u plz explain a bit more in case of undirected graph for DFS and BFS both.

0
0
  1. In undirected graph’s DFS there is no cross edge because, think if in given graph there is cross edge then in it’s DFS there is path in between both having cross edge so any one of them would be ancestor of one another for sure and if there is parent child relation (more general say ancestor) then it is not cross edge. 
  2. I think this was asked in 2016 also, and the correct values are |v-u| = {0,1}
2
2

Cross edge is not possible in a Depth First Tree of Graph … as suppose we are reaching a vertex v from u via some other node let w (root of u and v) .Now let u to v there is a cross edge it indicates that we could have reached v directly from u i.e v is a adjacent node to u in G. But that is not possible in Depth first Traversal v can only be explored from u via w, if v was adjacent to u in G then it should have been a child of u in Depth First tree of G.

1
1

7 Answers

51 votes
51 votes
Best answer
  1. Undirected graph cant have cross edges in DFS forest. (Only directed graphs can have)  ( Hence I is True)
    (If you do not agree just try it with taking examples. You cant draw)
     
  2. Just draw a triangle SAB. Source is S. Vertex A and B are at same level hence distance $1$.  So here $| i - j | = 0$.   (Hence II is false)


Hence answer is (A).

Anyway, II is simple to understand from the above explanation.
Those who did not get I, you may see Theorem $22.10$ in Cormen)

edited by
by

17 Comments

edited by
Oops sorry, the comment was about arguing that II is correct but I didn't really read that II talks about BFS and not DFS.
1
1
I am not really getting it. Can Someone take an example to prove the ans explaining both the points in the Question ?
Thanks in Advance
0
0
I will update in detail, with image.
0
0

Ahwan Could you pls comment the source/name of this book?

0
0
@Ahwan

in second statement, if we had less than or equal to instead of equality ,,i guess then 2nd option would have been correct , rt?

BFS on same graph yields a tree . And in any tree if there exist an edge (u,v) , then the difference between the level of u and v is always less  than or equal to 1.

Is my reasoning correct ??
0
0

Theorem 22.10

28
28
Please update your ANSWER....option D is the correct answer.
–1
–1
Try to understand it first, any way it was verified with official GATE keys. In fact all answers in GO.
0
0
This is not asked in the question but still : Backward Edge too not exist in the DFS of an Undirected Graph. (am I right ?)
0
0

How can the edge between A-B exist in BFT as per your example @Ahwan. Option ll seemed confusing to me . Are they talking about the graph G or BFT?? 

0
0

@Tuhin Dutta, its clearly mentioned in question that G is a graph and Tb is the breadth first search of tree. they are taking if there is one edge in G then difference of the depth of vertices of this edge in Tb will be 1. but this is not true in case of triangle as Ahwan shown in example.

 

@Dhiraj Raj, Only forward and cross edge doesn't exist in undirected DFT.

1
1
How can option 2 contain a triangle . because the definition of tree is - it is directed acyclic graph . if i is at depth 1 and j is also at depth 1 and their is an edge between them then that will form a cycle.

How is it possible?

Can someone please explain me.
0
0

@

Read the option II once again.

For every edge (u,v) of G.

It talks about graph G not Td or Tb, a graph can contain a cycle.

1
1
got it!
0
0

If 2nd option is |i-j|<=1 then it is true..

3
3
So, basically neither BFS or DFS yield cross edges. So (I) is wrong anyways.

In (II) condition we can have edges in the graph which are at the same level in the corresponding BFS traversal.

Say, node 1 is parent and node 2 and 3 are its children. So in DFS we will have edges (1,2) and (1,3). Here node 2 and node 3 are at the same depth i.e. depth 1, they are 1 level below node 0, while node 0 is at 0 depth (it is start of traversal). thus depth(1)-depth(2)=1-1=0. Statement (II) says it can only be 1. Thus it is false.
0
0

@Vishma P Das No, you’re wrong. BFS traversal of both undirected and directed graph can have cross edges.

0
0
21 votes
21 votes

I think the answer should be (A)

1 comment

Nice explanation bro. Good work.
0
0
13 votes
13 votes
Undirected graphs can't contain forward edges and cross edges since in those cases, edge $(v,u)$ would have already been traversed during DFS before we reach $u$ and try to visit $v$.

Let's say $(u,v)$ is an edge in $G$ and level of $u$ in $G$ is i. If we visit $u$ then after traversing every node of level $i$ we need to traverse node $v$. Because vertex $v$ is already in Queue so for next level traversal we need to visit $v$. That means $|d(v) − d(u)| \leq 1$.
edited by

2 Comments

yes , if it contains cross edges then it directly implies that the graph is disconnected but the graph given is connected(DFS tree)
0
0
What would happen if  we have only one edge in G? I believe this edge would be a cross edge according to the given definition.
0
0
3 votes
3 votes
I think none of these bcoz for bfs it can be zero and a graph can have cross edge

1 comment

i solvedit by counter examples and found none of these option d
–1
–1
Answer:

Related questions