3

A singly connected graph is a directed graph which has at most 1 path from u to v ∀ u,v.

I have thought of the following solution:

  1. Run DFS from any vertex.
  2. Now run DFS again but this time starting from the vertices in order of decreasing finish time. Run this DFS only for vertices which are not visited in some previous DFS. If we find a cross edge in the same component or a forward edge, then it is not Singly connected.
  3. If all vertices are finished and no such cross of forward edges, then singly connected.

O(V+E)

Is this right? Or is there a better solution.

Update : atmost 1 simple path.

Prashant
  • 923
  • 1
  • 11
  • 13
  • This is also called a [directed acyclic graph](http://en.wikipedia.org/wiki/Directed_acyclic_graph), and I think a BFS would be simpler and O(V). – Beta Nov 12 '13 at 14:35
  • How is it that a graph with cycles in not singly singly connected ? – Prashant Nov 12 '13 at 14:39
  • You have updated your question since my comment, but I see now that I was incorrect; a singly connected graph (according to your original definition) is acyclic, but a directed acyclic graph is not necessarily singly connected. I will expand my statement about BFS into an answer. – Beta Nov 12 '13 at 14:46
  • I must eat my words. If cycles are allowed, then the BFS approach gets really complicated. – Beta Nov 12 '13 at 19:41
  • yaa, me too. My solution too fails. I dont see any solution which has complexity less than O(V.(V+E)). – Prashant Nov 12 '13 at 20:19
  • Possible duplicate of [What is the most efficient way to determine if a directed graph is singly connected?](https://stackoverflow.com/questions/2511295/what-is-the-most-efficient-way-to-determine-if-a-directed-graph-is-singly-connec) – WY Hsu May 25 '17 at 10:22

3 Answers3

2

A graph is not singly connected if one of the two following conditions satisfies:

  1. In the same component, when you do the DFS, you get a road from a vertex to another vertex that has already finished it's search (when it is marked BLACK)

  2. When a node points to >=2 vertices from another component, if the 2 vertices have a connection then it is not singly connected. But this would require you to keep a depth-first forest.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Dang Manh Truong
  • 795
  • 2
  • 10
  • 35
  • 2
    This should have been a comment, not an answer. With a bit more rep, [you will be able to post comments](http://stackoverflow.com/privileges/comment). Until then, please do not use answers as a workaround. – Nathan Tuggy Mar 28 '15 at 05:21
0

A singly connected component is any directed graph belonging to the same entity. It may not necessarily be a DAG and can contain a mixture of cycles.

Every node has atleast some link(in-coming or out-going) with atleast one node for every node in the same component. All we need to do is to check whether such a link exists for the same component.

Singly Connected Component could be computed as follows:

  • Convert the graph into its undirected equivalent
  • Run DFS and set the common leader of each node

Run an iteration over all nodes. If all the nodes have the same common leader, the undirected version of the graph is singly connected.

Else, it contains of multiple singly connected subgraphs represented by their corresponding leaders.

npp
  • 11
  • 2
-1

Is this right?

No, it's not right. Considering the following graph which is not singly connected. The first component comes from a dfs beginning with vertex b and the second component comes from a dfs beginning with vertex a.


The right one:

Do the DFS, the graph is singly connected if all of the three following conditions satisfies:

  1. no foward edges
  2. no cross edges in the same component
  3. there is no more than 1 cross edges between any two of components
dae
  • 589
  • 2
  • 6
  • 20
  • Your "The Right one" answer is wrong! 3 is not sufficient. Suppose u is v's ancestor and w is in another tree, and (w,u) and (w,v) are both cross edges. then there's more than one path from w to v. – xdavidliu Dec 24 '20 at 01:50