3

According to the definition available in CLRS 3rd edition, a singly connected directed graph is the one where for every pair of vertices (u,v) there is at most 1 unique path from u->v. Now most of the answers that I have read, state that we run DFS from every vertex in the graph and if in any case we find a Cross edge or a Forward edge, then the graph is not singly connected. I can understand the concept for forward edges, but running this algo on this graph

1 --> 2 <-- 3 will give us the result that it is NOT singly connected whereas this graph is singly connected. We have a cross edge from 3 -> 2 or 1 -> 2 depending upon which vertext started this entire procedure (1 or 3) . If we start the DFS from vertex 2, then we have 2 cross edges 1 -> 2 and 3 -> 2.Can anyone clarify please ?

Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24
  • Are you (or they) maybe confusing cross and back edges? Because the presence of back edges (which are not mentioned here) is a definite indicator that a graph is not singly connected, while I agree with you that the presence of cross edges is not. – misberner Nov 24 '14 at 08:01
  • @misberner, consider the graph 1 -> 2 and an edge from 2 -> 1. Now this graph is also singly connected. We consider the pair (1,2) and we have just 1 path from 1 -> 2 i.e the single edge. Then we consider the pair (2,1) and we have a single unique path from 2->1 i.e the edge itself. Although, in the DFS starting from 1, we discover a back edge, this graph is still singly connected. – Sachin Malhotra Nov 24 '14 at 08:20
  • That is not true. A back edge means that there are cycles in the graph, and therefore you have infinitely many non-empty paths between nodes in the cycle: `1 -> 2`, `1 -> 2 -> 1 -> 2` etc. – misberner Nov 24 '14 at 09:18
  • @misberner true that. Sorry for the previous comment. I did not consider this scenario. Thank you for pointing it out – Sachin Malhotra Nov 24 '14 at 09:48

1 Answers1

1

The answer that suggests running DFS from every node means you should stop the DFS once you cannot continue (no outgoing edges left), and not start from a different node.

In this case, in your example, you will start (w.l.o) from 1, discover 2, and you are done. No back edgees
Next, is a completely new DFS, start from 3, discover 2, and done, again without back edges.

The idea is basically verifying the attribute by definition. You do a DFS from each node u until you either find that for each v there is at most one path from u to v (DFS is exhausted) or you found at some point a 2nd path from u to v, and then you are done.

amit
  • 175,853
  • 27
  • 231
  • 333
  • thank you for clarifying my doubt. But I am still not sure that finding just a cross edge in a graph, will lead to it being not single connected. Could you explain that part as well ? – Sachin Malhotra Nov 24 '14 at 08:22
  • @SachinMalhotra The idea is you run a DFS from a node `u` until you either find one of: (1) all paths to all nodes `v`, if there is a single path to each such `v`. (2) some node `v` that has two paths from `u` to `v` (the back edge leads to a vertex that you already visited, so you found the current path, and the path you discovered first time you visited it). These are basically your stop clauses. Is that part clear? – amit Nov 24 '14 at 08:25
  • yes, this part is clear. I understood the concept of back edges. What about cross edges ? This concept of cross edges bugs me every time This is what I read on a website as the answer to the question in CLRS :- Suppose we perform a DFS on the graph G starting with vertex u. If there is a forward or cross edge (v, w) in the DFS tree rooted at u (i.e., both v and w are descendants of u), then G has two paths from u to w: one uses the tree edges, the other uses tree edges from u to v followed by the forward or cross edge (v, w). – Sachin Malhotra Nov 24 '14 at 08:29
  • @SachinMalhotra If you started a DFS from `n`, and you found a cross edge `(u,v)` - that means there is a path from (1) `n` to `u`, (2)`n` to `v`, (3) `u` to `v`. But that means there is a path `n->...->u->v` (1+3), and also `n->...->v` (2). It doesn't really matters what is the type of the edge, the whole point is when you do a DFS - you abort and return false if you encounter a node you already discovered a path to, for each DFS iteration (done speratedly for each node in its own DFS). – amit Nov 24 '14 at 08:33