Weakly connected balanced digraph - algorithm

How can I prove that if a balanced digraph is weakly connected, then it is also strongly connected? (balanced digraph means that for every node, it's indegree and outdegree is the same and weakly connected means the non-directed version of this graph is connected).
What I can think of so far is: if the graph is balanced, it means it is a union of directed cycles. So if I remove any cycle, it will stay balanced. Also each vertex in the cycle has one edge coming into it and one edge leading out of it..
Then I guess I need to use some contradiction or induction to prove that the graph is strongly connected.. That's where I confused.

If two of those cycles intersect then they form a strongly connected component (since we can travel from any vertex in the cycle to the intersection of them then go around the other cycle and then come back again to complete the figure-8 )
Since the graph is weakly connected we know all the cycles intersect so therefore the graph is strongly connected.
I think you can flesh out the formality I left out.

Related

Euler Circuit in a Directed Graph

How to check if a directed graph is eulerian?
1) All vertices with nonzero degree belong to a single strongly connected component.
2) In degree is equal to the out degree for every vertex. Source: geeksforgeeks
Question:
In the given two conditions, is the first one strict? I mean why is it really necessary for the graph to be "strongly" connected graph? What if the graph is just connected?
I learned that condition 1 can be replaced with weakly connected graph. Again, what if the graph is just connected instead of weakly connected?
Will be glad to see some examples.
P.S: Consider condition 2 is always fulfilled in the above discussion. And by "just connected", I mean there exists a vertex in the graph from which all other vertices are reachable.
This is an interesting question. There is, to the best of my knowledge, no standardized meaning of "connected" in the context of a directed graph. The two general notions of connectivity in a directed graph are
strong connectivity, where for any pair of nodes u and v there's a path from u to v and a path from v to u, and
weak connectivity, where the undirected graph formed by ignoring the directionality on the arrowheads is connected.
Your version of the directed graph being "just connected" is slightly different than these definitions, but it's related to strong connectivity. Any directed graph can have its nodes partitioned into strongly connected components (SCCs), groups of nodes that can all reach one another. Those strongly connected components form a DAG, where each strongly connected component is a node and there's an edge from one SCC to another if one of the nodes in the first SCC has an edge to a node in the second SCC.
Your definition of the graph being "just connected" could then be pinned down like this:
"just connected": the DAG of SCCs has a source node that can reach all other nodes.
Notice that "just connected" implies weakly connected, but not the other way around.
It turns out that, in this case, if you have a graph where each node's indegree happens to equal its outdegree, then if the graph is "just connected," then it has an Euler circuit. If your graph is "just connected," then it's weakly connected. Then, we're going to claim that any weakly connected graph with indegrees equal to outdegrees must be strongly connected as well. To see this, pick any SCC in the DAG of SCCs with no incoming edges. Any edge entering any of the nodes in this SCC must come from within that SCC. As a result, if we went through each node in the SCC and added up the number of edges leaving that node, that total would match the number of incoming edges into each node in the SCC. But then, since the sum of indegrees of nodes equals the sum of outdegrees of the nodes, there can't then be any edges starting within this SCC and ending in another, since all edges are accounted for. Therefore, this SCC has no edges leaving it.
We've just shown that any source SCC must have no edges to any other SCCs. And since there is some node in some source SCC that can reach every node, this means that there are no other SCCs in the graph, so the graph has just one SCC and is therefore strongly connected.

Efficient algorithm that decides if an edge belongs to some cycle

I'm trying to struct an efficient algorithm gets undirected graph, and edge e(u,v), and decides if the edge belongs to some cycle in the graph ,but not all of the cycles!
My approach is to take out the edge (u,v) from the graph, and run BFS to see if v is still reachable from u. If yes then the original graph has a cycle containing e, otherwise there isn't.
But i'm not so sure how to tweak the algorithm that it will decide if the edge doesn't belong to all the cycles of the graph.
An undirected graph can contain an edge which belongs to all of its cycles graph only if this graph has a single cycle.
Let's look at an example. Edge (2,3) belongs to two cycles, but you always can find a third cycle to which such an edge doesn't belong.
After you have checked that the edge belongs to some cycle, you can check if this is the only cycle in the graph by removing this edge and checking if the reduced graph has any cycles at all. Thanks to #nomanpouigt for pointing that out.

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 can a breadth-first-search-tree include a cross-edge?

Well, I know that a breadth-first-search-tree of an undirected graph can't have a back edge. But I'm wondering how can it even have a cross-edge? I'm not able to image a spanning tree of a graph G constructed out of OFS, that contains a cross-edge.
The process of building a spanning tree using BFS over an undirected graph would generate the following types of edges:
Tree edges
Cross edges (connecting vertices on different branches)
A simple example: Imagine a triangle (a tri-vertice clique) - start a BFS from any node, and you'll reach the other two on the first step. You're left with an edge between them that does not belong to the spanning tree.
What about back-edges (connecting an ancestor with an non-immediate child) ? Well, as you point out, in BFS over an undirected graph you won't have them, since you would have used that edge when first reaching the ancestor.
In fact, you can make a stronger statement - all non-tree edges should be between vertices as the same level, or adjacent ones (you can't use that edge for the tree if the vertice on the other side is a sibling, like in the triangle case, or a sibling of the parent, that was not explored yet). Either way, it's falls under the definition of a cross-edge.
I had this same question...and the answer is that there are no cross edges in the BFS, but that the BFS tree itself encodes all the edges that would have been back-edges and forward-edges in the DFS tree as tree edges in the BFS tree, such that the remaining edges which the undirected graph has, but which are still not present in the BFS, are cross edges--and nothing else.
So the Boolean difference of the set of edges in the undirected graph and the edges in the BFS tree are all cross edges.
...As opposed to the DFS, where the set of missing edges may also include "Back Edges," "Forward Edges," and "Cross Edges."
I don't know why it is in the algorithmic parlance to say that both "tree edges and cross edges are in a BFS"
...I think it is just a short hand, and that in a math class, the professor would have written the relationship in set notation and unions (which I can't do on this stack exchange).

Minimize set of edges in a directed graph keeping connected components

Here is the full question:
Assume we have a directed graph G = (V,E), we want to find a graph G' = (V,E') that has the following properties:
G' has same connected components as G
G' has same component graph as G
E' is minimized. That is, E' is as small as possible.
Here is what I got:
First, run the strongly connected components algorithm. Now we have the strongly connected components. Now go to each strong connected component and within that SCC make a simple cycle; that is, a cycle where the only nodes that are repeated are the start/finish nodes. This will minimize the edges within each SCC.
Now, we need to minimize the edges between the SCCs. Alas, I can't think of a way of doing this.
My 2 questions are: (1) Does the algorithm prior to the part about minimizing edges between SCCs sound right? (2) How does one go about minimizing the edges between SCCs.
For (2), I know that this is equivalent to minimizing the number of edges in a DAG. (Think of the SCCs as the vertices). But this doesn't seem to help me.
The algorithm seems right, as long as you allow for closed walks (i.e. repeating vertices.) Proper cycles might not exist (e.g. in an "8" shaped component) and finding them is NP-hard.
It seems that it is sufficient to group the inter-component edges by ordered pairs of components they connect and leave only one edge in each group.
Regarding the step 2,minimize the edges between the SCCs, you could randomly select a vertex, and run DFS, only keeping the longest path for each pair of (root, end), while removing other paths. Store all the vertices searched in a list L.
Choose another vertex, if it exists in L, skip to the next vertex; if not, repeat the procedure above.

Resources