-1

I have a complete undirected graph with $V$ vertices and $\frac{V(V - 1)}{2}$ edges. Then, I remove $K$ edges $(a_i, b_i)$. I want to know if the graph is still connected after performing all the operations (so I want to delete those edges and then answer the question). Is there any faster way to do this than performing BFS/DFS algorithm? Those are linear time algorithms but in terms of edges which may be quite big to compute on a home PC for graphs with approximately $10^6$ vertices. $K$ of course will not be too big, let's say up to $10^6$.

Raphael
  • 72,336
  • 29
  • 179
  • 389
user128409235
  • 223
  • 1
  • 7

2 Answers2

2

To disconnect a complet graph $G=(V,E)$ into $V_1,V_2$ you have to remove at least $|V_1|*|V_2|$ edges (all the edges between elements of $V_1$ and elements of $V_2$).

Thus if $K<m*(|V|-m)$ you are sure that either the resulting graph is connected or there is a set of vertices $V_1$ such that $|V_1|<m$ which is disconnected.

Hence to check if your graph is connected you only need to check whether each vertex is connected to at least $m$ vertices. Thus you have to check only $m*|V|$ edges, which is better than BFS depending on $m$ (hence on $|K|$)

wece
  • 738
  • 3
  • 13
1

What you are looking for is called connected component labelling or connected component analysis. Withou any additional assumption on the graph, BFS or DFS might be best possible, as their running time is linear in the encoding size of the graph, namely O(m+n) where m is the number of edges and n is the number of vertices. That being said, if the number k is sufficiently small (namely smaller than the edge connectivity of the input), the graph still is connected after the edge removal.