Algorithm to find Articulation points in a directed graph - algorithm

I know how to find Articulation points for a undirected graph using DFS variant. But it seems like it is for undirected graph and only looks for back edge. But how to find Articulation points if my graph has forward edge or cross edge.I know i can always run dfs for every node and figure that out but is there any better algorithm.

Definition for Articulation points on directed graph is not unique.
It depends on what kind of connectedness you are considering. There are 3 kind of connections in directed graph
Strongly connected if there is a path from every vertex to every other vertex.
Connected if there is a path between any two nodes, but not in both directions.
Weakly connected if the graph is only connected if the arcs are replaced with undirected arcs.
If you are using second definition of connection, then U can use DFS for finding points.
I am not sure, but I think that if you define connection as Weakly connected then you can use DFS too. But it need to be proved.

Agreed that the definition of articulation is not as clear as in case of undirected graphs. However if we choose two particular nodes: source and sink and call any point that must occur on the path from source to sink articulation point, the definition is clear.
I call them unavoidable points and have got simple solution for finding them on my GitHub

Related

Directed Graph walk - visit every node at least once

I’m familiar with the Hamilton path for a directed graph - visit every node exactly once.
I’m looking for an algorithm to walk the graph so that I visit every node at least once. I can’t find the standard name for this problem, if any.
This graph is walkable - root-a-d-b-c
This graph is not walkable - because in my walk, if I reach c, I have no directed edge to reach a & d and conversely, if I walk to a, d; there’s no directed edge that takes me to b & c
Hope that clarifies the question? Is there a standard name for this type of graph walk and an algorithm to solve it?
Hamiltonian path
Finding at most 2 leafs in the graph
I don't know if there's a name for a directed "walkable" graph, but it's not too hard to determine of a graph is walkable or not:
Find all the strongly connected components using Tarjan's algorithn, for example
Make a new directed graph of the connections between SCCs. This will be a DAG, and your original graph is walkable if and only if this DAG is walkable.
To determine whether or not a DAG is walkable, do a topological sort. Then check that each vertex has an edge to the next.
Each of these steps takes linear time, so you get O(|V|+|E|) complexity for the whole algorithm.
Theorem: a directed graph is walkable if and only if its strongly connected components are totally ordered by reachability.
Proof sketch: (walkable implies condition) The existence of a walk implies that, for each two strongly connected components, a vertex from one or the other appears first in the walk. That component can reach the other. (condition implies walkable) Since there is full connectivity inside a strongly connected component, each is walkable on its own. We just have to concatenate the walks according to the total order, adding the necessary transitions.
The proof is constructive, so we can extract an algorithm.
Algorithm
Compute the strongly connected components.
Concatenate the strongly connected components in topological order. Actually Tarjan's algorithm will list them in reverse topological order, so this doesn't need to be a separate step.
For each adjacent pair in the previous list, use breadth-first search to find a shortest path.
In general, this algorithm does not find the shortest walk (that's NP-hard by reduction from Hamiltonian path).

Articulation Point of undirected graph

Does the type and number of articulation points vary when the entry point(root node) changes for an undirected graph?
If it changes then why does that happen?
I do understand that points might vary but why does the number of points vary?
Here is my graph :-
As stated in the Wiki article, articulation point is a vertex such that if it's removed than the number of connected components increases. There is nothing about entry points and DFS here: the definition depends only on the graph itself.
So, the answer to your question is: no, articulation points should not change if you traverse the graph from different nodes.
If you use a standard DFS-based algorithm to find articulation points, most likely you have a bug.

Make an undirected graph a strongly connected component (SCC)

Let G(V,E), an undirected, connected graph with no bridges at all. Describe an algorithm which direct the edges, so the new graph is an SCC.
My suggested algorithm
So we run DFS from an arbitrary vertex. We notice that since it's an undirected graph there are only tree-edges and back-edges (Right?). We connect edges accordingly (a tree-edge would be directed "down" and a back-edge would be directed "up").
A start of proof
We notice that the graph has no bridges. Therefore, every edge is part of some cycle. Therefore, the last edge to be discovered in some cycle must be a back-edge.
Now, I think the rest of the proof would need to show that we can always "climb" to the root, and so the graph is an SCC.
I'd be glad if you could help me connect the dots (or vertices XD)
Thanks
What you are looking for is a proof for Robbins' Theorem.
For a more formal proof you can look at this paper (See proof for theorem 2).
The below is not a formal proof but it's a way you can think of it:
As you already mentioned, since there are no bridges, every edge is a part of some cycle. Since you want your output graph to be SCC, a DFS on this output graph (from any vertex) must only have back-edges and tree-edges. It cannot have forward-edges or cross-edges.
Lets assume we have a forward-edge from s to t. This means that in the DFS we ran in order to build the graph, t was discovered in the sub-DFS (recursive call) of s and had no other gray or white adjacents. But this is not true because whenever we discover t in our DFS we would still have a gray adjacent.
Lets assume we have a cross-edge from s to t. This means that t's sub-DFS has ended before s was discovered. Again, this cannot happen in our DFS because either when discovering t first we would discover s in its sub-DFS or the opposite direction.
Here is a simple graph to help you see those cases.

Minimal addition to strongly connected graph

I have a set of nodes and set of directed edges between them. The edges have no weight.
How can I found minimal number of edges which has to be added to make the graph strongly connected (ie. there should be a path from every node to all others)? Does this problem have a name?
It's a really classical graph problem.
Run algorithm like Tarjan-SCC algorithm to find all SCCs. Consider
each SCC as a new vertice, link a edge between these new
vertices according to the origin graph, we can get a new graph.
Obviously, the new graph is a Directed Acyclic Graph(DAG).
In the DAG, find all vertices whose in-degree is 0, we define them
{X}; find all vertices whose out-degree is 0, we define
them {Y}.
If DAG has only one vertice, the answer is 0; otherwise, the answer
is max(|X|, |Y|).
Off the top of my head, it seems the simplest (fewest edges) way to make a directed graph strongly connected would be to just have a cycle involving all nodes; so the minimum number of edges would just be N where N is the number of nodes. If there are already edges, just do something like connect longest existing directed path to the next longest path that doesn't overlap with your current path, until you form a complete cycle (once your path contains all nodes, connect the ends to form the cycle.)
Not sure if there is a more formal definition of any of this, but is seems logical to me.
I would find all weakly connected components, and tie them up in a cycle.
EDIT:
To be more explicit, the idea is if you have WCCs W(1),...,W(n),
make all of W(i%n + 1) reachable from any node in W(i), for i=1 to n.

What is the most efficient way to determine if a directed graph is singly connected?

I am working on an assignment where one of the problems asks to derive an algorithm to check if a directed graph G=(V,E) is singly connected (there is at most one simple path from u to v for all distinct vertices u,v of V.
Of course you can brute force check it, which is what I'm doing right now, but I want to know if there's a more efficient way. Could anyone point me in the right direction?
There is a better answer for this question. you can do that in O(|V|^2). and with more effort you can do it in linear time.
First you find strongly connected components of G. in each strong component, you search to find this cases:
1) if there is a forward edge in this component, it is not singly connected,
2) if there is a cross edge in this component, it is not singly connected,
3) if there are at least two back edges in tree rooted at vertex u, to proper ancestors of u, then it is not singly connected.
this can be done in O(E). ( I think except for case 3. I couldn't implement it well!! ).
If none of cases above occurred, you should check whether there is a cross edge or a forward edge on G^SCC ( graph G, with strong components replaced with single nodes), since we don't have backedges, it can be done by repeating dfs on each vertex of this graph in O(|V|^2).
Have you tried DFS.
Run DFS for every vertex in the graph as source
If a visited vertex is encountered again, the graph is not singly connected
repeat for every unvisited vertex.
The graph is singly connected.
Complexity O(v^2), o(v) dfs as no repetition.
I don't agree that its complexity will be O(V^2), as In DFS we don't call it for every vertex as see in Introduction to algorithm book also, syntax is DFS(G). We only call DFS for whole graph not for any single vertex unlike BFS. So here in this case according to me we have to check it by calling DFS once.If a visited vertex is encountered again, the graph is not singly connected(definitely we have to call it for every disconnected component but it already included in the code). SO the complexity will be O(V+E). As here E=V therefore complexity should be O(V).
I thought of this :
1) Run DFS from any vertex, if all vertices are covered in the DFS with no forward edges(there can be no cross as else not all vertices will be covered), then it can be a potential candidate.
2) If a vertex(level j) which is found in the DFS has a back edge to level i then no other vertex found after it should have a back edge toward any vertex with level less than j and every vertex much be reachable to the root(checked with second DFS).
This does it in linear time if this is correct.
Take a look at the definition of simple path. A cyclic graph can be singly connected. DFS won't work for A->B, B->A, which is singly connected.
The following paper uses strongly connected component to solve this.
https://www.cs.umd.edu/~samir/grant/khuller99.ps
Run DFS once from each vertex. The graph is singly connected if and
only if there are no forward edges and there are no cross edges within a
component.
Complexity : O(V.E)

Resources