# data[].attributes.body
ECE-B
ASSIGNMENT-

# data[].attributes.body
15310

# data[].attributes.body
Assignment-4
connected components

# data[].attributes.body
ece -b assignment 4

# data[].attributes.body
ece -b assignment 4

# data[].attributes.body
153113
ECE B
CONNECTED COMPONENTS

# data[].attributes.body
(153014)
ECE-B
Assignment-4

# data[].attributes.body
ECE-B
Assignment-4

# data[].attributes.body
R.Kothaimeena
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE-B
Assignment-4

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ece -b assignment 4

# data[].attributes.body
(153045)
ece B
assignment 4

# data[].attributes.body
ECE-B
Assignment-4

# data[].attributes.body
ECE-B
ASSIGNMENT-4
CONNECTED COMPONENTS

# data[].attributes.body
ECE-B connected components

# data[].attributes.body
ECE-b assignment

# data[].attributes.body
ECE -B
ASSIGNMENT-4

# data[].attributes.body
ECE-b 153053 assignment 4

# data[].attributes.body
ECE-b assignment 4

# data[].attributes.body
ECE -B
Assignment-4

# data[].attributes.body
ECE-b assignment 4

# data[].attributes.body
(153310)
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE-B assignment 4

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE -B assignment

# data[].attributes.body
ECE-B 153117 assignment 4

# data[].attributes.body
ECE - B
ssignment -4

# data[].attributes.body
ECE-B
ASSIGNMENT-4
CONNECTED COMPONENTS

# data[].attributes.body
153302
ece b

# data[].attributes.body
E C E - B

# data[].attributes.body
ECE-B
ASSIGNMENT-4
Connected components

# data[].attributes.body
ECE B Assignment

# data[].attributes.body
153044
ECE-B
ASSIGNMENT-

# data[].attributes.body
ECE-B
153115
connected components

# data[].attributes.attachment_link.title
File:Pseudoforest.svg - Wikipedia, the free encyclopedia

# data[].attributes.body
ECE-B
ASSIGNMENT

# data[].attributes.body
ECE B
ASSIGNMENT 4

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE-B

ASSIGNMENT4

# data[].attributes.body
ECE-B
assignment-4

# data[].attributes.body
153044
ECE-B
ASSIGNMENT-IV

# data[].attributes.body
ECE-B

# data[].attributes.body
ECE-B
Assignment-4

# data[].attributes.body
ECE-

# data[].attributes.body
ECE

# data[].attributes.body
ECE-B
ASSIGNMENT-IV

# data[].attributes.body
ECE-B
ASSIGNMENT-4
CONNECTED COMPONENTS

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE:B
ASSIGNMENT  4
Connected Components

# data[].attributes.attachment_link.title
File:Pseudoforest.svg - Wikipedia, the free encyclopedia

# data[].attributes.body
ECE.B IIIrd SEM

ASSIGNMENT-4

# data[].attributes.headline
S.M.GAYATHRIStrongly Connected ComponentsA directed graph is strongly connected if there is a path between all pairs of vertices. A strongly connected component (SCC) of a directed graph is a maximal strongly connected subgraph. For example, there are 3 SCCs in the following graph.We can find all strongly connected components in O(V+E) time using Kosaraju’s algorithm. Following is detailed Kosaraju’s algorithm.1) Create an empty stack ‘S’ and do DFS traversal of a graph. In DFS traversal, after calling recursive DFS for adjacent vertices of a vertex, push the vertex to stack. In the above graph, if we start DFS from vertex 0, we get vertices in stack as 1, 2, 4, 3, 0.2) Reverse directions of all arcs to obtain the transpose graph.3) One by one pop a vertex from S while S is not empty. Let the popped vertex be ‘v’. Take v as source and do DFS (call DFSUtil(v)). The DFS starting from v prints strongly connected component of v. In the above example, we process vertices in order 0, 3, 4, 2, 1 (One by one popped from stack).How does this work?The above algorithm is DFS based. It does DFS two times. DFS of a graph produces a single tree if all vertices are reachable from the DFS starting point. Otherwise DFS produces a forest. So DFS of a graph with only one SCC always produces a tree. The important point to note is DFS may produce a tree or a forest when there are more than one SCCs depending upon the chosen starting point. For example, in the above diagram, if we start DFS from vertices 0 or 1 or 2, we get a tree as output. And if we start from 3 or 4, we get a forest. To find and print all SCCs, we would want to start DFS from vertex 4 (which is a sink vertex), then move to 3 which is sink in the remaining set (set excluding 4) and finally any of the remaining vertices (0, 1, 2). So how do we find this sequence of picking vertices as starting points of DFS? Unfortunately, there is no direct way for getting this sequence. However, if we do a DFS of graph and store vertices according to their finish times, we make sure that the finish time of a vertex that connects to other SCCs (other that its own SCC), will always be greater than finish time of vertices in the other SCC (See this for proof). For example, in DFS of above example graph, finish time of 0 is always greater than 3 and 4 (irrespective of the sequence of vertices considered for DFS). And finish time of 3 is always greater than 4. DFS doesn’t guarantee about other vertices, for example finish times of 1 and 2 may be smaller or greater than 3 and 4 depending upon the sequence of vertices considered for DFS. So to use this property, we do DFS traversal of complete graph and push every finished vertex to a stack. In stack, 3 always appears after 4, and 0 appear after both 3 and 4.In the next step, we reverse the graph. Consider the graph of SCCs. In the reversed graph, the edges that connect two components are reversed. So the SCC {0, 1, 2} becomes sink and the SCC {4} becomes source. As discussed above, in stack, we always have 0 before 3 and 4. So if we do a DFS of the reversed graph using sequence of vertices in stack, we process vertices from sink to source (in reversed graph). That is what we wanted to achieve and that is all needed to print SCCs one by one.Following is C++ implementation of Kosaraju’s algorithm.C++Java// C++ Implementation of Kosaraju's algorithm to print all SCCs#include #include #include using namespace std; class Graph{    int V;    // No. of vertices    list *adj;    // An array of adjacency lists     // Fills Stack with vertices (in increasing order of finishing    // times). The top element of stack has the maximum finishing     // time    void fillOrder(int v, bool visited[], stack &Stack);     // A recursive function to print DFS starting from v    void DFSUtil(int v, bool visited[]);public:    Graph(int V);    void addEdge(int v, int w);     // The main function that finds and prints strongly connected    // components    void printSCCs();     // Function that returns reverse (or transpose) of this graph    Graph getTranspose();}; Graph::Graph(int V){    this->V = V;    adj = new list[V];} // A recursive function to print DFS starting from vvoid Graph::DFSUtil(int v, bool visited[]){    // Mark the current node as visited and print it    visited[v] = true;    cout << v << " ";     // Recur for all the vertices adjacent to this vertex    list::iterator i;    for (i = adj[v].begin(); i != adj[v].end(); ++i)        if (!visited[*i])            DFSUtil(*i, visited);} Graph Graph::getTranspose(){    Graph g(V);    for (int v = 0; v < V; v++)    {        // Recur for all the vertices adjacent to this vertex        list::iterator i;        for(i = adj[v].begin(); i != adj[v].end(); ++i)        {            g.adj[*i].push_back(v);        }    }    return g;} void Graph::addEdge(int v, int w){    adj[v].push_back(w); // Add w to v’s list.} void Graph::fillOrder(int v, bool visited[], stack &Stack){    // Mark the current node as visited and print it    visited[v] = true;     // Recur for all the vertices adjacent to this vertex    list::iterator i;    for(i = adj[v].begin(); i != adj[v].end(); ++i)        if(!visited[*i])            fillOrder(*i, visited, Stack);     // All vertices reachable from v are processed by now, push v     Stack.push(v);} // The main function that finds and prints all strongly connected // componentsvoid Graph::printSCCs(){    stack Stack;     // Mark all the vertices as not visited (For first DFS)    bool *visited = new bool[V];    for(int i = 0; i < V; i++)        visited[i] = false;     // Fill vertices in stack according to their finishing times    for(int i = 0; i < V; i++)        if(visited[i] == false)            fillOrder(i, visited, Stack);     // Create a reversed graph    Graph gr = getTranspose();     // Mark all the vertices as not visited (For second DFS)    for(int i = 0; i < V; i++)        visited[i] = false;     // Now process all vertices in order defined by Stack    while (Stack.empty() == false)    {        // Pop a vertex from stack        int v = Stack.top();        Stack.pop();         // Print Strongly connected component of the popped vertex        if (visited[v] == false)        {            gr.DFSUtil(v, visited);            cout << endl;        }    }} // Driver program to test above functionsint main(){    // Create a graph given in the above diagram    Graph g(5);    g.addEdge(1, 0);    g.addEdge(0, 2);    g.addEdge(2, 1);    g.addEdge(0, 3);    g.addEdge(3, 4);     cout << "Following are strongly connected components in "            "given graph \n";    g.printSCCs();     return 0;}Run on IDEOutput:Following are strongly connected components in given graph
0 1 2
3
4Time Complexity: The above algorithm calls DFS, fins reverse of the graph and again calls DFS. DFS takes O(V+E) for a graph represented using adjacency list. Reversing a graph also takes O(V+E) time. For reversing the graph, we simple traverse all adjacency lists.The above algorithm is asymptotically best algorithm, but there are other algorithms like Tarjan’s algorithmand path-based which have same time complexity but find SCCs using single DFS. The Tarjan’s algorithm is discussed in the following post.Tarjan’s Algorithm to find Strongly Connected ComponentsApplications:SCC algorithms can be used as a first step in many graph algorithms that work only on strongly connected graph.In social networks, a group of people are generally strongly connected (For example, students of a class or any other common place). Many people in these groups generally like some common pages or play common games. The SCC algorithms can be used to find such groups and suggest the commonly liked pages or games to the people in the group who have not yet liked commonly liked a page or played a game.References:http://en.wikipedia.org/wiki/Kosaraju%27s_algorithmhttps://www.youtube.com/watch?v=PZQ0Pdk15RAYou may also like to see Tarjan’s Algorithm to find Strongly Connected Components.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above Company Wise Coding Practice    Topic Wise Coding Practice16 Comments Category: Graph Tags: GraphRelated Posts:Stepping NumbersClone an Undirected GraphLongest Path in a Directed Acyclic Graph | Set 2Find Shortest distance from a guard in a BankTopological Sort of a graph using departure time of vertexFinding minimum vertex cover size of a graph using binary searchFind the number of Islands | Set 2 (Using Disjoint Set)Check if two nodes are on same path in a treePost navigationPrevious post in categoryNext post in category(Login to Rate and Mark)4.2 Average Difficulty : 4.2/5.0Based on 24 vote(s)  Add to TODO List  Mark as DONEWriting code in comment? Please use code.geeksforgeeks.org, generate link and share the link here.Siva KrishnaHow Facebook implements a connection between two friends?. Is it directed or indirect?. I think it is undirected, then how SCC algo can be applied for finding “recommend friends”.Roni César de CastroIs it correct to say that “0 1 2″ is one of the SCCs instead of “0 2 1″? Shouldn’t it respect the direction of the original digraph.Amar Vashishth

# data[].attributes.subject
S.M.GAYATHRIStrongly Connected ComponentsA directed graph is strongly connected if there is a path between all pairs of vertices. A strongly connected component (SCC) of a directed graph is a maximal strongly connected subgraph. For example, there are 3 SCCs in the following graph.We can find all strongly connected components in O(V+E) time using Kosaraju’s algorithm. Following is detailed Kosaraju’s algorithm.1) Create an empty stack ‘S’ and do DFS traversal of a graph. In DFS traversal, after calling recursive DFS for adjacent vertices of a vertex, push the vertex to stack. In the above graph, if we start DFS from vertex 0, we get vertices in stack as 1, 2, 4, 3, 0.2) Reverse directions of all arcs to obtain the transpose graph.3) One by one pop a vertex from S while S is not empty. Let the popped vertex be ‘v’. Take v as source and do DFS (call DFSUtil(v)). The DFS starting from v prints strongly connected component of v. In the above example, we process vertices in order 0, 3, 4, 2, 1 (One by one popped from stack).How does this work?The above algorithm is DFS based. It does DFS two times. DFS of a graph produces a single tree if all vertices are reachable from the DFS starting point. Otherwise DFS produces a forest. So DFS of a graph with only one SCC always produces a tree. The important point to note is DFS may produce a tree or a forest when there are more than one SCCs depending upon the chosen starting point. For example, in the above diagram, if we start DFS from vertices 0 or 1 or 2, we get a tree as output. And if we start from 3 or 4, we get a forest. To find and print all SCCs, we would want to start DFS from vertex 4 (which is a sink vertex), then move to 3 which is sink in the remaining set (set excluding 4) and finally any of the remaining vertices (0, 1, 2). So how do we find this sequence of picking vertices as starting points of DFS? Unfortunately, there is no direct way for getting this sequence. However, if we do a DFS of graph and store vertices according to their finish times, we make sure that the finish time of a vertex that connects to other SCCs (other that its own SCC), will always be greater than finish time of vertices in the other SCC (See this for proof). For example, in DFS of above example graph, finish time of 0 is always greater than 3 and 4 (irrespective of the sequence of vertices considered for DFS). And finish time of 3 is always greater than 4. DFS doesn’t guarantee about other vertices, for example finish times of 1 and 2 may be smaller or greater than 3 and 4 depending upon the sequence of vertices considered for DFS. So to use this property, we do DFS traversal of complete graph and push every finished vertex to a stack. In stack, 3 always appears after 4, and 0 appear after both 3 and 4.In the next step, we reverse the graph. Consider the graph of SCCs. In the reversed graph, the edges that connect two components are reversed. So the SCC {0, 1, 2} becomes sink and the SCC {4} becomes source. As discussed above, in stack, we always have 0 before 3 and 4. So if we do a DFS of the reversed graph using sequence of vertices in stack, we process vertices from sink to source (in reversed graph). That is what we wanted to achieve and that is all needed to print SCCs one by one.Following is C++ implementation of Kosaraju’s algorithm.C++Java// C++ Implementation of Kosaraju's algorithm to print all SCCs#include #include #include using namespace std; class Graph{    int V;    // No. of vertices    list *adj;    // An array of adjacency lists     // Fills Stack with vertices (in increasing order of finishing    // times). The top element of stack has the maximum finishing     // time    void fillOrder(int v, bool visited[], stack &Stack);     // A recursive function to print DFS starting from v    void DFSUtil(int v, bool visited[]);public:    Graph(int V);    void addEdge(int v, int w);     // The main function that finds and prints strongly connected    // components    void printSCCs();     // Function that returns reverse (or transpose) of this graph    Graph getTranspose();}; Graph::Graph(int V){    this->V = V;    adj = new list[V];} // A recursive function to print DFS starting from vvoid Graph::DFSUtil(int v, bool visited[]){    // Mark the current node as visited and print it    visited[v] = true;    cout << v << " ";     // Recur for all the vertices adjacent to this vertex    list::iterator i;    for (i = adj[v].begin(); i != adj[v].end(); ++i)        if (!visited[*i])            DFSUtil(*i, visited);} Graph Graph::getTranspose(){    Graph g(V);    for (int v = 0; v < V; v++)    {        // Recur for all the vertices adjacent to this vertex        list::iterator i;        for(i = adj[v].begin(); i != adj[v].end(); ++i)        {            g.adj[*i].push_back(v);        }    }    return g;} void Graph::addEdge(int v, int w){    adj[v].push_back(w); // Add w to v’s list.} void Graph::fillOrder(int v, bool visited[], stack &Stack){    // Mark the current node as visited and print it    visited[v] = true;     // Recur for all the vertices adjacent to this vertex    list::iterator i;    for(i = adj[v].begin(); i != adj[v].end(); ++i)        if(!visited[*i])            fillOrder(*i, visited, Stack);     // All vertices reachable from v are processed by now, push v     Stack.push(v);} // The main function that finds and prints all strongly connected // componentsvoid Graph::printSCCs(){    stack Stack;     // Mark all the vertices as not visited (For first DFS)    bool *visited = new bool[V];    for(int i = 0; i < V; i++)        visited[i] = false;     // Fill vertices in stack according to their finishing times    for(int i = 0; i < V; i++)        if(visited[i] == false)            fillOrder(i, visited, Stack);     // Create a reversed graph    Graph gr = getTranspose();     // Mark all the vertices as not visited (For second DFS)    for(int i = 0; i < V; i++)        visited[i] = false;     // Now process all vertices in order defined by Stack    while (Stack.empty() == false)    {        // Pop a vertex from stack        int v = Stack.top();        Stack.pop();         // Print Strongly connected component of the popped vertex        if (visited[v] == false)        {            gr.DFSUtil(v, visited);            cout << endl;        }    }} // Driver program to test above functionsint main(){    // Create a graph given in the above diagram    Graph g(5);    g.addEdge(1, 0);    g.addEdge(0, 2);    g.addEdge(2, 1);    g.addEdge(0, 3);    g.addEdge(3, 4);     cout << "Following are strongly connected components in "            "given graph \n";    g.printSCCs();     return 0;}Run on IDEOutput:Following are strongly connected components in given graph
0 1 2
3
4Time Complexity: The above algorithm calls DFS, fins reverse of the graph and again calls DFS. DFS takes O(V+E) for a graph represented using adjacency list. Reversing a graph also takes O(V+E) time. For reversing the graph, we simple traverse all adjacency lists.The above algorithm is asymptotically best algorithm, but there are other algorithms like Tarjan’s algorithmand path-based which have same time complexity but find SCCs using single DFS. The Tarjan’s algorithm is discussed in the following post.Tarjan’s Algorithm to find Strongly Connected ComponentsApplications:SCC algorithms can be used as a first step in many graph algorithms that work only on strongly connected graph.In social networks, a group of people are generally strongly connected (For example, students of a class or any other common place). Many people in these groups generally like some common pages or play common games. The SCC algorithms can be used to find such groups and suggest the commonly liked pages or games to the people in the group who have not yet liked commonly liked a page or played a game.References:http://en.wikipedia.org/wiki/Kosaraju%27s_algorithmhttps://www.youtube.com/watch?v=PZQ0Pdk15RAYou may also like to see Tarjan’s Algorithm to find Strongly Connected Components.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above Company Wise Coding Practice    Topic Wise Coding Practice16 Comments Category: Graph Tags: GraphRelated Posts:Stepping NumbersClone an Undirected GraphLongest Path in a Directed Acyclic Graph | Set 2Find Shortest distance from a guard in a BankTopological Sort of a graph using departure time of vertexFinding minimum vertex cover size of a graph using binary searchFind the number of Islands | Set 2 (Using Disjoint Set)Check if two nodes are on same path in a treePost navigationPrevious post in categoryNext post in category(Login to Rate and Mark)4.2 Average Difficulty : 4.2/5.0Based on 24 vote(s)  Add to TODO List  Mark as DONEWriting code in comment? Please use code.geeksforgeeks.org, generate link and share the link here.Siva KrishnaHow Facebook implements a connection between two friends?. Is it directed or indirect?. I think it is undirected, then how SCC algo can be applied for finding “recommend friends”.Roni César de CastroIs it correct to say that “0 1 2″ is one of the SCCs instead of “0 2 1″? Shouldn’t it respect the direction of the original digraph.Amar Vashishth

# data[].attributes.body
ECE-B
ASSINGMENT

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
ECE-B
ASSIGNMENT

# data[].attributes.attachment_link.title
File:Pseudoforest.svg - Wikipedia, the free encyclopedia

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.attachment_link.readable_text
This graph becomes disconnected when the right-most node in the gray area on the left is removed

This graph becomes disconnected when the dashed edge is removed.

In mathematics and computer science, connectivity is one of the basic concepts of graph theory: it asks for the minimum number of elements (nodes or edges) that need to be removed to separate the remaining nodes into two or more isolated subgraphs. It is closely related to the theory of network flow problems. The connectivity of a graph is an important measure of its resilience as a network.

With vertex 0, this graph is disconnected. The rest of the graph is connected.

In an undirected graph G, two vertices u and v are called connected if G contains a path from u to v. Otherwise, they are called disconnected. If the two vertices are additionally connected by a path of length 1 (that is, they are the endpoints of a single edge), the vertices are called adjacent.

A graph is said to be connected if every pair of vertices in the graph is connected. This means that there is a path between every pair of vertices. An undirected graph that is not connected is called disconnected. An undirected graph G is therefore disconnected if there exist two vertices in G such that no path in G has these vertices as endpoints. A graph with just one vertex is connected. An edgeless graph with two or more vertices is disconnected.

A directed graph is called weakly connected if replacing all of its directed edges with undirected edges produces a connected (undirected) graph. It is unilaterally connected or unilateral (also called semiconnected) if it contains a directed path from u to v or a directed path from v to u for every pair of vertices . It is strongly connected, or simply strong, if it contains a directed path from u to v and a directed path from v to u for every pair of vertices .

A connected component is a maximal connected subgraph of an undirected graph. Each vertex belongs to exactly one connected component, as does each edge. A graph is connected if and only if it has exactly one connected component.

The strong components are the maximal strongly connected subgraphs of a directed graph.

A or separating set of a connected graph G is a set of vertices whose removal renders G disconnected. The vertex connectivity (where G is not a complete graph) is the size of a minimal vertex cut. A graph is called k -vertex-connected or k -connected if its vertex connectivity is k or greater.

More precisely, any graph G (complete or not) is said to be k-vertex-connected if it contains at least k + 1 vertices, but does not contain a set of k − 1 vertices whose removal disconnects the graph; and is defined as the largest k such that G is k-connected. In particular, a complete graph with n vertices, denoted , has no vertex cuts at all, but .

A vertex cut for two vertices u and v is a set of vertices whose removal from the graph disconnects u and v. The local connectivity is the size of a smallest vertex cut separating u and v. Local connectivity is symmetric for undirected graphs; that is, . Moreover, except for complete graphs, equals the minimum of over all nonadjacent pairs of vertices .

2-connectivity is also called biconnectivity and 3-connectivity is also called triconnectivity. A graph G which is connected but not 2-connected is sometimes called separable.

Analogous concepts can be defined for edges. In the simple case in which cutting a single, specific edge would disconnect the graph, that edge is called a . More generally, an edge cut of G is a set of edges whose removal renders the graph disconnected. The edge-connectivity is the size of a smallest edge cut, and the local edge-connectivity of two vertices is the size of a smallest edge cut disconnecting u from v. Again, local edge-connectivity is symmetric. A graph is called k-edge-connected if its edge connectivity is k or greater.

A graph is said to be maximally connected if its connectivity equals its minimum degree. A graph is said to be maximally edge-connected if its edge-connectivity equals its minimum degree.

Super- and hyper-connectivity

A graph is said to be super-connected or super-κ if every minimum vertex cut isolates a vertex. A graph is said to be hyper-connected or hyper-κ if the deletion of each minimum vertex cut creates exactly two components, one of which is an isolated vertex. A graph is semi-hyper-connected or semi-hyper-κ if any minimum vertex cut separates the graph into exactly two components.

More precisely: a G connected graph is said to be super-connected or super-κ if all minimum vertex-cuts consist of the vertices adjacent with one (minimum-degree) vertex. A G connected graph is said to be super-edge-connected or super-λ if all minimum edge-cuts consist of the edges incident on some (minimum-degree) vertex.

A cutset X of G is called a non-trivial cutset if X does not contain the neighborhood N( superconnectivity u) of any vertex u ∉ X. Then the G is of

A non-trivial edge-cut and the edge-superconnectivity are defined analogously.[6]

Menger's theorem

One of the most important facts about connectivity in graphs is Menger's theorem, which characterizes the connectivity and edge-connectivity of a graph in terms of the number of independent paths between vertices.

If u and v are vertices of a graph G, then a collection of paths between u and v is called independent if no two of them share a vertex (other than u and v themselves). Similarly, the collection is edge-independent if no two paths in it share an edge. The number of mutually independent paths between u and v is written as , and the number of mutually edge-independent paths between u and v is written as .

Menger's theorem asserts that for distinct vertices u, v, equals , and if u is also not adjacent to v then equals . This fact is actually a special case of the max-flow min-cut theorem.

The problem of determining whether two vertices in a graph are connected can be solved efficiently using a search algorithm, such as breadth-first search. More generally, it is easy to determine computationally whether a graph is connected (for example, by using a disjoint-set data structure), or to count the number of connected components. A simple algorithm might be written in pseudo-code as follows:

Begin at any arbitrary node of the graph G.

Proceed from that node using either depth-first or breadth-first search, counting all nodes reached.

Once the graph has been entirely traversed, if the number of nodes counted is equal to the number of nodes of G, the graph is connected; otherwise it is disconnected.

By Menger's theorem, for any two vertices u and v in a connected graph G, the numbers and can be determined efficiently using the max-flow min-cut algorithm. The connectivity and edge-connectivity of G can then be computed as the minimum values of and , respectively.

In O(log computational complexity theory, SL is the class of problems log-space reducible to the problem of determining whether two vertices in a graph are connected, which was proved to be equal to L by Omer Reingold in 2004. Hence, undirected graph connectivity may be solved in n) space.

The problem of computing the probability that a Bernoulli random graph is connected is called network reliability and the problem of computing whether two given vertices are connected the ST-reliability problem. Both of these are #P-hard.

Number of connected graphs

The number of distinct connected labeled graphs with n nodes is tabulated in the On-Line Encyclopedia of Integer Sequences as sequence A001187. The first few non-trivial terms are

The number and images of connected graphs with 4 nodes

The vertex- and edge-connectivities of a disconnected graph are both 0.

1-connectedness is equivalent to connectedness for graphs of at least two vertices.

The complete graph on n vertices has edge-connectivity equal to n − 1. Every other simple graph on n vertices has strictly smaller edge-connectivity.

In a tree, the local edge-connectivity between any two distinct vertices is 1.

The vertex-connectivity of a graph is less than or equal to its edge-connectivity. That is, .

The edge-connectivity for a graph with at least 2 vertices is less than or equal to the minimum degree of the graph because removing all the edges that are incident to a vertex of minimum degree will disconnect that vertex from the rest of the graph.

For a vertex-transitive graph of degree d ≤ 4, or for any (undirected) minimal Cayley graph of degree d, or for any symmetric graph of degree d, both kinds of connectivity are equal: .

# data[].attributes.attachment_link.description
In mathematics and computer science, connectivity is one of the basic concepts of graph theory: it asks for the minimum number of elements (nodes or edges) that need to be removed to separate the remaining nodes into two or more isolated subgraphs.

# data[].attributes.body
ECE-B
ASSIGNMENT IV-
CONNECTED COMPONENTS

# data[].attributes.body
ECE-B
ASSIGNMENT

# data[].attributes.body
ECE-B
ASSIGNMENT 4

# data[].attributes.body
ECE-B
ASSIGNMENT-

# data[].attributes.attachment_link.readable_text
In mathematics and computer science, connectivity is one of the basic concepts of graph theory: it asks for the minimum number of elements (nodes or edges) that need to be removed to separate the remaining nodes into two or more isolated subgraphs. It is closely related to the theory of network flow problems. The connectivity of a graph is an important measure of its resilience as a network.

In an undirected graph G, two u and v are called connected if G contains a path from u to v. Otherwise, they are called disconnected. If the two vertices are additionally connected by a path of length 1, i.e. by a single edge, the vertices are called adjacent.

A graph is said to be connected if every pair of vertices in the graph is connected. This means that there is a path between every pair of vertices. An undirected graph that is not connected is called disconnected. An undirected graph G is therefore disconnected if there exist two vertices in G such that no path in G has these vertices as endpoints. A graph with just one vertex is connected. An edgeless graph with two or more vertices is disconnected.

A directed graph is called weakly connected if replacing all of its directed edges with undirected edges produces a connected (undirected) graph. It is unilaterally connected or unilateral (also called semiconnected) if it contains a directed path from u to v or a directed path from v to u for every pair of vertices u, v. It is strongly connected, or simply strong, if it contains a directed path from u to v and a directed path from v to u for every pair of vertices u, v.

A connected component is a maximal connected subgraph of an undirected graph. Each vertex belongs to exactly one connected component, as does each edge. A graph is connected if and only if it has exactly one connected component.

The strong components are the maximal strongly connected subgraphs of a directed graph.

A or separating set of a connected graph G is a set of vertices whose removal renders G disconnected. The vertex connectivity (where G is not a complete graph) is the size of a minimal vertex cut. A graph is called k -vertex-connected or k -connected if its vertex connectivity is k or greater.

More precisely, any graph G (complete or not) is said to be k-vertex-connected if it contains at least k+1 vertices, but does not contain a set of k − 1 vertices whose removal disconnects the graph; and is defined as the largest k such that G is k-connected. In particular, a complete graph with n vertices, denoted , has no vertex cuts at all, but .

A vertex cut for two vertices u and v is a set of vertices whose removal from the graph disconnects u and v. The local connectivity is the size of a smallest vertex cut separating u and v. Local connectivity is symmetric for undirected graphs; that is, . Moreover, except for complete graphs, equals the minimum of over all nonadjacent pairs of vertices u, v.

2-connectivity is also called biconnectivity and 3-connectivity is also called triconnectivity. A graph G which is connected but not 2-connected is sometimes called separable.

Analogous concepts can be defined for edges. In the simple case in which cutting a single, specific edge would disconnect the graph, that edge is called a . More generally, an edge cut of G is a set of edges whose removal renders the graph disconnected. The edge-connectivity is the size of a smallest edge cut, and the local edge-connectivity of two vertices u, v is the size of a smallest edge cut disconnecting u from v. Again, local edge-connectivity is symmetric. A graph is called k-edge-connected if its edge connectivity is k or greater.

A graph is said to be maximally connected if its connectivity equals its minimum degree. A graph is said to be maximally edge-connected if its edge-connectivity equals its minimum degree.

Super- and hyper-connectivity

A graph is said to be super-connected or super-κ if every minimum vertex cut isolates a vertex. A graph is said to be hyper-connected or hyper-κ if the deletion of each minimum vertex cut creates exactly two components, one of which is an isolated vertex. A graph is semi-hyper-connected or semi-hyper-κ if any minimum vertex cut separates the graph into exactly two components.

More precisely: a G connected graph is said to be super-connected or super-κ if all minimum vertex-cuts consist of the vertices adjacent with one (minimum-degree) vertex. A G connected graph is said to be super-edge-connected or super-λ if all minimum edge-cuts consist of the edges incident on some (minimum-degree) vertex.

A cutset X of G is called a non-trivial cutset if X does not contain the neighborhood N(u) of any vertex u ∉ X. Then the superconnectivity κ1 of G is:

κ1(G) = min{|X| : X is a non-trivial cutset}.

A non-trivial edge-cut and the edge-superconnectivity λ1(G) are defined analogously.

Menger's theorem

One of the most important facts about connectivity in graphs is Menger's theorem, which characterizes the connectivity and edge-connectivity of a graph in terms of the number of independent paths between vertices.

If u and v are vertices of a graph G, then a collection of paths between u and v is called independent if no two of them share a vertex (other than u and v themselves). Similarly, the collection is edge-independent if no two paths in it share an edge. The number of mutually independent paths between u and v is written as , and the number of mutually edge-independent paths between u and v is written as .

Menger's theorem asserts that for distinct vertices u, v, equals , and if u is also not adjacent to v then equals . This fact is actually a special case of the max-flow min-cut theorem.

The problem of determining whether two vertices in a graph are connected can be solved efficiently using a search algorithm, such as breadth-first search. More generally, it is easy to determine computationally whether a graph is connected (for example, by using a disjoint-set data structure), or to count the number of connected components. A simple algorithm might be written in pseudo-code as follows:

Begin at any arbitrary node of the graph, G

Proceed from that node using either depth-first or breadth-first search, counting all nodes reached.

Once the graph has been entirely traversed, if the number of nodes counted is equal to the number of nodes of G, the graph is connected; otherwise it is disconnected.

By Menger's theorem, for any two vertices u and v in a connected graph G, the numbers and can be determined efficiently using the max-flow min-cut algorithm. The connectivity and edge-connectivity of G can then be computed as the minimum values of and , respectively.

In computational complexity theory, O(log SL is the class of problems log-space reducible to the problem of determining whether two vertices in a graph are connected, which was proved to be equal to L by Omer Reingold in 2004. Hence, undirected graph connectivity may be solved in n) space.

The problem of computing the probability that a Bernoulli random graph is connected is called network reliability and the problem of computing whether two given vertices are connected the ST-reliability problem. Both of these are #P-hard.

Number of connected graphs

The number of distinct connected labeled graphs with n nodes is tabulated in the On-Line Encyclopedia of Integer Sequences as sequence A001187. The first few non-trivial terms are

# data[].attributes.attachment_link.description
In mathematics and computer science, connectivity is one of the basic concepts of graph theory: it asks for the minimum number of elements (nodes or edges) that need to be removed to separate the remaining nodes into two or more isolated subgraphs.

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.attachment_link.readable_text
In graph theory, a component of an undirected graph is an induced subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the rest of the graph. For example, the graph shown in the illustration has three components. A vertex with no incident edges is itself a component. A graph that is itself connected has exactly one component, consisting of the whole graph. Components are also sometimes called connected components.

An alternative way to define components involves the equivalence classes of an equivalence relation that is defined on the vertices of the graph. In an undirected graph, a vertex v is reachable from a vertex u if there is a path from u to v. In this definition, a single vertex is counted as a path of length zero, and the same vertex may occur more than once within a path. Reachability is an equivalence relation, since:

It is reflexive: There is a trivial path of length zero from any vertex to itself.

It is symmetric: If there is a path from u to v, the same edges form a path from v to u.

It is transitive: If there is a path from u to v and a path from v to w, the two paths may be concatenated together to form a path from u to w.

The components are then the induced subgraphs formed by the equivalence classes of this relation.

The number of components is an important topological invariant of a graph. In topological graph theory it can be interpreted as the zeroth Betti number of the graph. In algebraic graph theory it equals the multiplicity of 0 as an eigenvalue of the Laplacian matrix of the graph. It is also the index of the first nonzero coefficient of the chromatic polynomial of a graph. Numbers of components play a key role in the Tutte theorem characterizing graphs that have perfect matchings, and in the definition of graph toughness.

It is straightforward to compute the components of a graph in linear time (in terms of the numbers of the vertices and edges of the graph) using either breadth-first search or depth-first search. In either case, a search that begins at some particular vertex v will find the entire component containing v (and no more) before returning. To find all the components of a graph, loop through its vertices, starting a new breadth first or depth first search whenever the loop reaches a vertex that has not already been included in a previously found component. Hopcroft & Tarjan (1973) describe essentially this algorithm, and state that at that point it was "well known".

There are also efficient algorithms to dynamically track the components of a graph as vertices and edges are added, as a straightforward application of O(|O(log | disjoint-set data structures. These algorithms require amortized O( α( n)) time per operation, where adding vertices and edges and determining the component in which a vertex falls are both operations, and α( n) is a very slow-growing inverse of the very quickly growing Ackermann function. A related problem is tracking components as all edges are deleted from a graph, one by one; an algorithm exists to solve this with constant time per query, and time to maintain the data structure; this is an amortized cost of V|) per edge deletion. For forests, the cost can be reduced to , or V|) amortized cost per edge deletion ( Shiloach & Even 1981).

Researchers have also studied algorithms for finding components in more limited models of computation, such as programs in which the working memory is limited to a logarithmic number of bits (defined by the complexity class L). Lewis & Papadimitriou (1982) asked whether it is possible to test in logspace whether two vertices belong to the same component of an undirected graph, and defined a complexity class SL of problems logspace-equivalent to connectivity. Finally Reingold (2008) succeeded in finding an algorithm for solving this connectivity problem in logarithmic space, showing that L = SL.

In random graphs the sizes of components are given by a random variable, which, in turn, depends on the specific model.

The model has three regions with seemingly different behavior:

Subcritical

All components are simple and very small, the largest component has size ;

Critical

;

Supercritical

where is the positive solution to the equation

where and are respectively the largest and the second largest components. All other components have their sizes of the order

Hopcroft, J.; Tarjan, R. (1973), "Algorithm 447: efficient algorithms for graph manipulation", Communications of the ACM, 16 (6): 372-378, doi:10.1145/362248.362272

Lewis, Harry R.; Papadimitriou, Christos H. (1982), "Symmetric space-bounded computation", Theoretical Computer Science, 19 (2): 161-187, doi:10.1016/0304-3975(82)90058-5

Reingold, Omer (2008), "Undirected connectivity in log-space", Journal of the ACM, 55 (4): Article 17, 24 pages, doi:10.1145/1391289.1391291

Shiloach, Yossi; Even, Shimon (1981), "An on-line edge-deletion problem", Journal of the ACM, 28 (1): 1-4, doi:10.1145/322234.322235

# data[].attributes.attachment_link.description
In graph theory, a component of an undirected graph is an induced subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the rest of the graph. For example, the graph shown in the illustration has three components.

# data[].attributes.body
153307
ECE-B
ASSIGNMENT-54

# data[].attributes.body
ECE:B
ASSIGNMENT IV

# data[].attributes.body
153023

ECE-B

Assignment-4

# data[].attributes.body
ECE-B
ASSIGNMENT-4

# data[].attributes.body
AP/ECE

OOP and Data Structures

Assignment - IV

Connected Components