Articulation Point of undirected graph - algorithm

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.

Related

Is my understanding of the concept of centres of directed, weighted graphs correct?

I'm currently working on a problem that requires me to find the centre of a directed, weighted graph. I am seeking to ensure that my understanding of some related concepts is correct.
For instance, let's say we have some sets of nodes represented as links:
/wiki/Flow_network
/wiki/Braess%27_paradox
/wiki/Flow_network
/wiki/Circulation_problem
/wiki/Braess%27_paradox
/wiki/new
/wiki/new
/wiki/Braess%27_paradox
Each set has two nodes (links), where the first node is the "source" node and has a directed edge to the second node.
As I understand it, each of the nodes have the following eccentricities:
ecc(FN) = 2
ecc(CP) = 0
ecc(BP) = 1
ecc(new) = 1
The radius of the graph would be 0, since this is the smallest eccentricity.
And since the centre of a graph is the set of nodes which have eccentricity = radius, the centre of this directed, weighted graph would be CP?
One reason I'm seeking to ensure that my understanding is correct is because this "centre" seems weird when one draws the graph in question.
Have I understood this correctly?
Before reading, note that I'm not a mathematician, and I'm simply trying to attempt to answer this with implementation in mind. The definition of the center of a graph is indeed the set of all vertices of minimum eccentricity. The problem is that this is usually a concept used on undirected graphs. If your graph is undirected, you won't run into issues like the one you experienced here where your vertex of least eccentricity doesn't connect to any other vertices. By definition, you are correct that this is the "Center" of the graph. However, this would obviously not be the center if the graph were undirected and is probably useless to you in anything other than the theoretical context. If you're simply trying to find the theoretical center of the graph, this is probably your answer, at least if you follow the definitions of of eccentricity, radius, and center found here: https://en.wikipedia.org/wiki/Distance_(graph_theory). If you're trying to find something more to the effect of the center of an undirected graph, where the vertex returned is the least far away from all other vertices, maybe try finding the vertex with lowest eccentricity that has a path to all or most other nodes, or maybe set the eccentricity of a vertex to infinity if it doesn't connect to any other nodes. Either of those suggestions will likely get you more useful results. If you want a more theoretical view, head over to the math stackexchange: https://math.stackexchange.com/.

Algorithm to find Articulation points in a directed graph

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

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.

How to find the minimum set of vertices in a Directed Graph such that all other vertices can be reached

Given a directed graph, I need to find the minimum set of vertices from which all other vertices can be reached.
So the result of the function should be the smallest number of vertices, from which all other vertices can be reached by following the directed edges.
The largest result possible would be if there were no edges, so all nodes would be returned.
If there are cycles in the graph, for each cycle, one node is selected. It does not matter which one, but it should be consistent if the algorithm is run again.
I am not sure that there is an existing algorithm for this? If so does it have a name? I have tried doing my research and the closest thing seems to be finding a mother vertex
If it is that algorithm, could the actual algorithm be elaborated as the answer given in that link is kind of vague.
Given I have to implement this in javascript, the preference would be a .js library or javascript example code.
From my understanding, this is just finding the strongly connected components in a graph. Kosaraju's algorithm is one of the neatest approaches to do this. It uses two depth first searches as against some later algorithms that use just one, but I like it the most for its simple concept.
Edit: Just to expand on that, the minimum set of vertices is found as was suggested in the comments to this post :
1. Find the strongly connected components of the graph - reduce each component to a single vertex.
2. The remaining graph is a DAG (or set of DAGs if there were disconnected components), the root(s) of which form the required set of vertices.
[EDIT #2: As Jason Orendorff mentions in a comment, finding the feedback vertex set is overkill and will produce a vertex set larger than necessary in general. kyun's answer is (or will be, when he/she adds in the important info in the comments) the right way to do it.]
[EDIT: I had the two steps round the wrong way... Now we should guarantee minimality.]
Call all of the vertices with in-degree zero Z. No vertex in Z can be reached by any other vertex, so it must be included in the final set.
Using a depth-first (or breadth-first) traversal, trace out all the vertices reachable from each vertex in Z and delete them -- these are the vertices already "covered" by Z.
The graph now consists purely of directed cycles. Find a feedback vertex set F which gives you a smallest-possible set of vertices whose removal would break every cycle in the graph. Unfortunately as that Wikipedia link shows, this problem is NP-hard for directed graphs.
The set of vertices you're looking for is Z+F.

Minimal path - all edges at least once

I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.
I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.
Can anybody help me? Thanks
Edit>> All edges of that graph have the same cost - for instance 1
Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).
If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.
Key quote (the second half for the directed version):
The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.
I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.
what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here
And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here
I think it might be worth while just simply writing which vertices are odd and then find which combo of them will lead to the least amount of extra time (if the weights are for times or distances) then the total length will be every edge weight plus the extra. For example, if the odd order vertices are A,B,C,D try AB&CD then AC&BD and so on. (I'm not sure if this is a specifically named method, it just worked for me).
edit: just realised this mostly only works for undirected graphs.
The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):
When all of the edges of a connected graph are directed and the graph
is symmetric, there is a particularly simple and attractive algorithm for
specifying an Euler tour...
The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at
any node n, except the root r of the arborescence, specify any order for
the edges directed away from n so long as the edge of the arborescence
is last in the ordering. For the root r, specify any order at all for the
edges directed away from r.
This algorithm was used by van Aardenne-Ehrenfest and de Bruin to
enumerate all Euler tours in a certain directed graph [ 1 ].

Resources