how to find Connected Component dynamically - algorithm

Using disjoint-set data structure can easily get connected component of Graph. And, it just supports Incremental Connected Components.
However, in my case, removing edge is very common so that I am looking for an algorithm or new structure can maintain Connected Components fully dynamically(including adding and removing edge)
Thanks

Poly-logarithmic deterministic fully-dynamic algorithms for connectivity, minimum spanning tree, 2-edge, and biconnectivity (Holm, de Lichtenberg and Thorup 2001) gives an algorithm that allows an arbitrary sequence of edge insertions, deletions and connectivity queries, with updates (insertions and deletions) taking O(log(n)^2) amortised time, and queries taking O(log(n)/log(log(n))) time, with n being the number of vertices in the graph. These time bounds assume that the graph starts with no edges.
I only skimmed the first 2 of its 38 pages, but don't be (too) scared -- the paper describes a bunch of new algorithms on dynamic graphs (that is, graphs that can be efficiently modified over time) of which connectivity is the simplest.

Related

Detect Disconnected Subtours in Graph

I have used an Integer Linear Program (ILP) to generate a path from source to sink in a graph. Each variable Pij in the solution represents a transition from node i to j in the path. Unfortunately, the result is a collection of 2 or more disconnected directed subtours, that do not have a transition from one to the other, thereby making the path useless.
There are ways to prevent subtours from happening, but they first require the detection of such disconnected subtours in primitive solution. Now here's my question: how do I detect disconnected subtours?
Some features of the problem:
I have the primitive solution in the form of both, an adjacency matrix and adjacency list
The source and sink vertices are distinct. No looping back to source
Any vertex in the graph may be traversed any number of times. No rule that it should be traversed only once
My thoughts:
If there are disconnected subtours, then they are actually acting as independent, directed graphs on their own, and hence the problem can be restated as detecting all graphs within an adjacency matrix/list
My first instict was to detect all Strongly Connected Components (SCC's) in the graph, but I retracted after realising that Kosaraju's and other such algorithms are infeasible over disconnected subtours. I can apply such algorithms within each subtour, though.
What could solve the problem (According to me):
Modification of existing SCC detection algorithms to operate on disconnected graphs
Adaptation of graph traversal algorithms to operate on disconnected graphs
Any existing method (of course)
Experience of anyone to have faced a similar issue.

Design a O(V+E) algorithm for determining at what point a graph becomes disconnected when deleting edges sequentially from a list of edges S

You are given a connected graph G and a series of edges S. One at a time, an edge from S is removed from G. You then check to see if G is still connected. If G is no longer connected, you return the edge. Otherwise, you remove the edge from the graph and continue.
My initial thought was to use Tarjan's bridge finding algorithm, which builds a DFS tree and then checks to see if a given vertex has a back-edge connecting one of its descendants to it or one of its ancestors. If it does not, then it is a bridge.
You can find all of the bridges in O(V+E) time while building the tree, but I am having problems adapting Tarjan's algorithm to account for deletions. Every time you delete an edge, the tree changes, and I am having trouble keeping the algorithm at O(V+E) time. Any thoughts?
You can do this fairly easily in almost-linear, O(E * alpha(V)) time, where alpha is the ridiculously-slowly-growing inverse-Ackermann function, using a disjoint-set data structure. The trick is to reverse S and add edges, so you ask about when G first becomes connected, rather than disconnected. The incremental connectivity problem is quite a bit easier than the decremental connectivity case.
Given an implementation of disjoint-set, you can augment it to track the number of components, and a graph is connected exactly when there is only one component. If you start with n components, then before any Union(x, y) operation, check whether x and y belong to the same component. If they don't, then the union operation will reduce the graph's components by 1.
For your graph, you'll need to preprocess S to find all of the edges in G that are not in S, and add these to the disjoint-set data structure first. Then, if adding S[i] causes the graph to be connected for the first time, the answer is i, since we've already added S[i+1], S[i+2], ... S[n-1].
Optimal Complexity
The inverse-Ackermann function is at most 4 for any input that fits in our universe, so our Union-find algorithm is usually considered 'pretty much linear'. However, if that's not good enough...
You can do this in O(V+E), although it's quite complex, and probably of mostly theoretical interest. Gabow and Tarjan's 1984 paper found an algorithm that supports Union-Find in O(1) amortized cost per operation if we know the order of all union operations, which we do here. It still uses the disjoint-set data structure, but adds additional auxiliary structures to cache node information on small sets.
Some pseudocode is provided in the paper, but you'll probably need to implement this yourself or look for implementations online. It also only works in the word RAM model, since it fundamentally relies on manipulating small bit-strings in constant time to use them as lookup tables (a fairly standard assumption, but you'll need to do some low-level bit manipulation).
Find the bridge edges
FOR E in S
IF E is a bridge
STOP
remove E
IF E1 is disconnected ( zero edges on E1 )
STOP
IF E2 is disconnected
STOP
E1 and E2 are the vertices connected by E

Efficient way to check whether a graph has become disconnected?

Using a disjoint set forest, we can efficiently check incrementally whether a graph has become connected while adding edges to it. (Or rather, it allows us to check whether two vertices already belong to the same connected component.) This is useful, for example, in Kruskal's algorithm for computing the minimum spanning tree.
Is there a similarly efficient data structure and algorithm to check whether a graph has become disconnected while removing edges from it?
More formally, I have a connected graph G = (V, E) from which I'm iteratively removing edges one by one. Without loss of generality, let's say these are e_1, e_2, and so on. I want to stop right before G becomes disconnected, so I need a way to check whether the removal of e_i will make the graph disconnected. This can of course be done by removing e_i and then doing a breadth-first or depth-first search from an arbitrary vertex, but this is an O(|E|) operation, making the entire algorithm O(|E|²). I'm hoping there is a faster way by somehow leveraging results from the previous iteration.
I've looked at partition refinement but it doesn't quite solve this problem.
There’s a family of data structures that are designed to support queries of the form “add an edge between two nodes,” “delete an edge between two nodes,” and “is there a path from node x to node y?” This is called the dynamic connectivity problem and there are many data structures that you can use to solve it. Unfortunately, these data structures tend to be much more complicated than a disjoint-set forest, so you may want to search around to see if you can find a ready-made implementation somewhere.
The layered forest structure of Holm et al works by maintaining a hierarchy of spanning forests for the graph and doing some clever bookkeeping with edges to avoid rescanning them when seeing if two parts of the graph are still linked. It supports adding and deleting edges in amortized time O(log2 n) and queries of the form “are these two nodes connected?” in time O(log n / log log n).
A more recent randomized structure called the randomized cutset was developed by Kapron et al. It has worst-case O(log5 n) costs for all three operations (IIRC).
There might be a better way to solve your particular problem that doesn’t require these heavyweight approaches, but I figured I’d mention these in case they’re helpful.

Real world applications where spanning tree data structure is used

Does anyone of you know any real world applications where spanning tree data structure is used?
In networking, we use Minimum spanning tree algorithm often. So the problem is as stated here, given a graph with weighted edges, find a tree of edges with the minimum total weight that satisfies these three properties: connected, acyclic, and consisting of |V| - 1 edges. (In fact, any two of the three conditions imply the third condition.)
as an example,
For instance, if you have a large local area network with a lot of
switches, it might be useful to find a minimum spanning tree so that
only the minimum number of packets need to be relayed across the
network and multiple copies of the same packet don't arrive via
different paths (remember, any two nodes are connected via only a
single path in a spanning tree).
Other real-world problems include laying out electrical grids,
reportedly the original motivation for Boruvka's algorithm, one of the
first algorithms for finding minimum spanning trees. It shouldn't be
surprising that it would be better to find a minimum spanning tree
than just any old spanning tree; if one spanning tree on a network
would involve taking the most congested, slowest path, it's probably
not going to be ideal!
There are many other applications apart from the computer networks, i listed the references below:
Network design:
– telephone, electrical, hydraulic, TV cable, computer, road
The standard application is to a problem like phone network design. You have a business with several offices; you want to lease phone lines to connect them up with each other; and the phone company charges different amounts of money to connect different pairs of cities. You want a set of lines that connects all your offices with a minimum total cost. It should be a spanning tree, since if a network isn’t a tree you can always remove some edges and save money.
Approximation algorithms for NP-hard problems:
– traveling salesperson problem, Steiner tree
A less obvious application is that the minimum spanning tree can be used to approximately solve the traveling salesman problem. A convenient formal way of defining this problem is to find the shortest path that visits each point at least once.
Note that if you have a path visiting all points exactly once, it’s a special kind of tree. For instance in the example above, twelve of sixteen spanning trees are actually paths. If you have a path visiting some vertices more than once, you can always drop some edges to get a tree. So in general the MST weight is less than the TSP weight, because it’s a minimization over a strictly larger set.
On the other hand, if you draw a path tracing around the minimum spanning tree, you trace each edge twice and visit all points, so the TSP weight is less than twice the MST weight. Therefore this tour is within a factor of two of optimal.
Indirect applications:
– max bottleneck paths
– LDPC codes for error correction
– image registration with Renyi entropy
– learning salient features for real-time face verification
– reducing data storage in sequencing amino acids in a protein
– model locality of particle interactions in turbulent fluid flows
– autoconfig protocol for Ethernet bridging to avoid cycles in a network
Cluster analysis:
k clustering problem can be viewed as finding an MST and deleting the k-1 most
expensive edges.
you can read the details from here, and here, and for a demo check here please.

How to detect if breaking an edge will make a graph disjoint?

I have a graph that starts off with a single, root node. Nodes are added one by one to the graph. At node creation time, they have to be linked either to the root node, or to another node, by a single edge. Edges can also be created and deleted (one by one, between any two nodes). Nodes can be deleted one at a time. Node and edge creation, deletion operations can happen in any arbitrary order.
OK, so here's my question: When an edge is deleted, is it possible do determine, in constant time (i.e. with an O(1) algorithm), if doing this will divide the graph into two disjoint subgraphs? If it will, then which side of the edge will the root node belong?
I'm willing to maintain, within reasonable limits, any additional data structure that can facilitate the derivation of this information.
Maybe it is not possible to do it in O(1), if so any pointers to literature will be appreciated.
Edit: The graph is a directed graph.
Edit 2: OK, maybe I can restrict the case to deletion of edges from the root node. [Edit 3: not, actually] Also, no edge lands into the root node.
To speed things up a little over the obvious O(|V|+|E|) solution, you could keep a spanning tree which is fairly easy to update as the graph is changed.
If an edge not in the spanning tree is deleted, then the graph isn't disconnected and do nothing. If an edge in the spanning tree is deleted, then you must try to find a new path between those two vertices (if you find one, use it to update the spanning tree, otherwise the graph is disconnected).
So, best case O(1), worst-case O(|V|+|E|), but fairly simple to implement anyway.
Is this a directed graph? The below assumes undirected.
What you are looking for is whether the given edge is a Bridge in the graph. I believe this can be found using a traversal looking for cycles containing that edge and would be O(|V| + |E|).
O(1) is too much to ask.
You might find that looking to maintain 2-edge connected components in dynamic graphs could be useful to you.
Eppstein et al have a paper on this: http://www.ics.uci.edu/~eppstein/pubs/EppGalIta-TR-93-20.pdf
which can maintain 2-edge connected components, in a graph of n nodes where edge insertions and deletions are allowed. It has O(sqrt(n)) time per update and O(log n) time per query.
So any time you delete, you can query in O(logn) to determine if the number of 2-edge connected components has changed. I suppose it can also tell you which component a specific node is in.
This paper is more general and applies to other graph problems, not only 2 edge connected components.
I suggest you look for bridges and dynamic 2-edge connectivity to get you started.
Hope that helps.
as said by Moron just before, you are actually looking for a Bridge in your graph.
Now a Bridge is an edge that has the described attribute and also originates and ends up in Cut Vertexes. Cut vertex is exactly what a Bridge is, but in a vertex (node) edition.
So the only way (though quite bending the initial data structure hypothesis) I can think of, to get a O(1) complexity for this, is if you first check every node in your graph if it is a Cut Vertex and then simply in constant time checking if the edge you want to delete is a attached to one of those two.
Finding if a node in a graph is a Cut Vertex takes O(m+n) where m = # edges and n= # nodes.
Cheers

Resources