A k-connected graph is a type of graph where removing k-1 vertices (and edges) from the graph does not disconnect it.
In other words, there are at least k distinct paths between any two vertices in the graph, and the graph remains connected even if k-1 vertices or edges are removed. The parameter k is known as the connectivity of the graph. The higher the connectivity of a graph, the more robust it is against failures or attacks.
A 4-connected Graph
Properties of k-connected Graph:
- Robustness: A k-connected graph is more robust against vertex or edge failures than a graph with lower connectivity. Removing k-1 vertices or edges from a k-connected graph does not disconnect it.
- Minimum degree: In a k-connected graph, every vertex has a degree of at least k. This means that the graph is densely connected and has many paths between its vertices.
- Separability: A graph is k-connected if and only if it is not separable into two disconnected subgraphs by removing k-1 vertices.
- Augmentation: Every k-connected graph can be augmented to a (k+1)-connected graph by adding edges between any two sets of k vertices that are not already connected.
- Planarity: In a planar k-connected graph, the number of vertices is at least 2k, and the number of edges is at least 3k – 6.
How to identify a k-connected Graph?
- Brute force approach: One way to identify if a graph is k-connected is to remove all possible subsets of k-1 vertices (or edges) and check if the graph remains connected after each removal. This approach is not efficient for large graphs, but it can be used for small graphs.
- Max-flow min-cut theorem: According to the Max-flow min-cut theorem, the maximum flow in a graph is equal to the minimum cut in the graph. Therefore, we can use a max-flow algorithm to find the minimum cut of a graph, and if the minimum cut is greater than or equal to k, then the graph is k-connected.
- Connectivity algorithm: We can use a connectivity algorithm such as Tarjan’s algorithm or Hopcroft–Karp algorithm to find all the cut-vertices and cut-edges in a graph. If there are no cut-vertices and cut-edges of size less than k-1, then the graph is k-connected.
- DFS Algorithm: First we, check if K is greater than or equal to 2 and less than the total number of vertices in the graph. If K is greater than or equal to the number of vertices in the graph minus one, then the graph cannot be K-connected. Next, for each vertex in the graph, perform a DFS traversal and count the number of vertices that are visited. If the number of visited vertices is less than K, then the graph is not K-connected.
If the above condition is not satisfied for any vertex in the graph, then the graph is K-connected.
Sudo code for dfs algorithm
function isKConnected(Graph G, int K): visited = {False} * |V(G)| if K < 2 or K >= |V(G)|: return False for each vertex u in G: count = 0 DFS(u, visited, count) if count < K: return False return True function DFS(vertex v, visited, count): visited[v] = True count += 1 for each adjacent vertex w of v: if not visited[w]: DFS(w, visited, count)
Implementation:
C++
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector< int > adj[N]; bool visited[N]; void DFS( int u, int & count) { visited[u] = true ; count++; for ( int v : adj[u]) { if (!visited[v]) { DFS(v, count); } } } bool isKConnected( int n, int K) { if (K < 2 || K >= n) { return false ; } for ( int u = 0; u < n; u++) { memset (visited, false , sizeof (visited)); int count = 0; DFS(u, count); if (count < K) { return false ; } } return true ; } int main() { int n, m, K; n = 5, m = 4, K = 2; // modify these values as needed adj[0] = {1, 2}; adj[1] = {2, 3}; adj[2] = {3, 4}; adj[3] = {4, 5}; /* cin >> n >> m >> K; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); }*/ if (isKConnected(n, K)) { cout << "Graph is K-connected." << endl; } else { cout << "Graph is not K-connected." << endl; } return 0; } |
Python3
# Set recursion limit to prevent RecursionError for large graphs import sys sys.setrecursionlimit( 10 * * 6 ) # Maximum number of nodes in the graph N = 100005 # Create an adjacency list to store the graph adj = [[] for _ in range (N)] # Boolean array to keep track of visited nodes visited = [ False ] * N # Depth-first search function to visit all nodes in a connected component def DFS(u, count): visited[u] = True count[ 0 ] + = 1 for v in adj[u]: if not visited[v]: DFS(v, count) # Function to check if the graph is K-connected def isKConnected(n, K): # If K is less than 2 or greater than or equal to n, then the graph is not K-connected if K < 2 or K > = n: return False # For each node u in the graph, perform a DFS to count the number of nodes reachable from u for u in range (n): global visited visited = [ False ] * n count = [ 0 ] DFS(u, count) # If the number of reachable nodes is less than K, then the graph is not K-connected if count[ 0 ] < K: return False # If all nodes satisfy the condition, then the graph is K-connected return True # Example input values n = 5 m = 4 K = 2 edges = [( 1 , 2 ), ( 2 , 3 ), ( 3 , 4 ), ( 4 , 5 )] # Add input edges to the adjacency list for u, v in edges: adj[u].append(v) adj[v].append(u) # Check if the graph is K-connected and print the result if isKConnected(n, K): print ( "Graph is K-connected." ) else : print ( "Graph is not K-connected." ) #Contributed by siddharth aher |
Output
Graph is not K-connected.
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!