Question

In: Computer Science

Is it always possible to make an undirected graph with two connected components connected by adding...

Is it always possible to make an undirected graph with two connected components connected by adding a single edge?

• Why or why not? (Proof or counter example) [if true, give a proof, if false, give counter example]
• Does the same hold true for directed graphs (and strongly connected components rather than connected components)? (Proof or counter example) [if true, give a proof, if false, give counter example]

Solutions

Expert Solution

Connected components in undirected graphs

A connected component of an undirected graph G = (V, E) is a maximal set of vertices S ⊂ V such that for each u ∈ S and v ∈ S, there exists a path in G from vertex u to vertex v.

Definition (Formal Definition)

Let u ∼ v if and only if G has a path from vertex u to vertex v. This is an equivalence relation (it is symmetric, reflexive, and transitive). Then, a connected component of G is an equivalence class of this relation ∼. Recall that the equivalence class of a vertex u over a relation ∼ is the set of all vertices v such that u ∼ v.

Algorithm to find connected components in a undirected graph

In order to find a connected component of an undirected graph, we can just pick a vertex and start doing a search (BFS or DFS) from that vertex. All the vertices we can reach from that vertex compose a single connected component. To find all the connected components, then, we just need to go through every vertex, finding their connected components one at a time by searching the graph. Note however that we do not need to search from a vertex v if we have already found it to be part of a previous connected component. Hence, if we keep track of what vertices we have already encountered, we will only need to perform one BFS for each connected component.

Proof.

When searching from a particular vertex v,

we will clearly never reach any nodes outside the connected component with DFS or BFS. So we just need to prove that we will in fact reach all connected vertices.

We can prove this by induction:

Consider the vertices at minimum distance i from vertex v.

Call these vertices “level i” vertices.

If BFS or DFS succesfully reaches all vertices at level i, then they must reach all vertices at level i + 1, since each veriex at distance i + 1 from v must be connected to some vertex at distance i from v.

This is the inductive step, and for the base case, DFS or BFS will clearly reach all vertices at level 0 (just v itself).

So indeed this algorithm will find each connected component correctly.

The searches in the above algorithm take total time O(|E|+|V |),

because each BFS or DFS call takes linear time in the number of edges and vertices for its component, and each component is only searched once, so all searches will take time linear in the total number of edges and vertices.

Connectivity in directed graphs

How can we extend the notion of connected components to directed graphs?

Definition (Strongly connected component (SCC))

A strongly connected component in a directed graph G = (V, E) is a maximal set of vertices S ⊂ V such that each vertex v ∈ S has a path to each other vertex u ∈ S. This is the same as the definition using equivalence classes for undirected graphs, except now u ∼ v if and only if there is a path from u to v AND a path from v to u.

Definition (Weakly connected component)

Let G = (V, E) be a directed graph, and let G0 be the undirected graph that is formed by replacing each directed edge of G with an undirected edge. Then the weakly connected components of G are exactly the connected components of G0 .

Input:

a directed graph G = (V, E), in adjacency list representation. Assume that the vertices V are labeled 1, 2, 3, . . . , n.

1. Let Grev denote the graph G after the orientation of all arcs have been reversed.

2. Run the DFS-Loop subroutine on Grev, processing vertices in any arbitrary order, to obtain a finishing time f(v) for each vertex v ∈ V .

3. Run the DFS-Loop subroutine on G, processing vertices in decreasing order of f(v), to assign a “leader” to each vertex v ∈ V . The leader of a vertex v will be the source vertex that the DFS that discovered v started from.

4. The strongly connected components of G correspond to vertices of G that share a common leader.

A 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.


Related Solutions

Construct a connected undirected graph with 25 or more nodes. - Draw your graph in a...
Construct a connected undirected graph with 25 or more nodes. - Draw your graph in a diagram. - Draw the adjacency matrix of your graph. - Draw the adjacency list of your graph. - Run the BFS algorithm on your graph and complete the chart discussed in class. Detailed steps, including the changes of node color, predecessor, etc., as discussed in class, are required.
Give an algorithm that constructs an undirected connected graph, which allows for labeling of the n...
Give an algorithm that constructs an undirected connected graph, which allows for labeling of the n vertices u - v <= k for every edge (u,v), where k is some constant. All nodes have a unique label.
Which graph search method will be better for finding a cycle in an undirected graph: a...
Which graph search method will be better for finding a cycle in an undirected graph: a BTS or a DFS? In detail, describe (create) an algorithm for finding a cycle in any undirected graph, explaining why the algorithm assures to find a cycle if there exists one.
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph...
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph contains a cycle, then your algorithm should output one. (It should not output all cycles in the graph, just one of them.) The running time of your algorithm should be O(m + n) for a graph with n nodes and m edges.
Write a program in java that detects if there is a cycle in an undirected graph...
Write a program in java that detects if there is a cycle in an undirected graph using DFS Two lines of input: 1. Two integers V for the number of vertices and E for the number of edges respectively. 2. List of integers that shows how the graph is connected. Ex input: 4 4 01020323 Output: Graph contains cycle Ex input: 5 4 01020314 Output: Graph doesn't contains cycle
In a simple undirected graph H the sum of vertex degrees is 60. What is the...
In a simple undirected graph H the sum of vertex degrees is 60. What is the smallest possible number of vertices in this graph? What is the largest possible number of vertices in the graph?
You are given an undirected graph G = ( V, E ) in which the edge...
You are given an undirected graph G = ( V, E ) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight from 1 to W, where W is a constant (independent of the number of edges or vertices). Show that it is possible to compute the single-source shortest paths in such a graph in O(E+V) time.
You are given an undirected graph A. The problem P asks, if there exists a cycle...
You are given an undirected graph A. The problem P asks, if there exists a cycle that contains more than half of the nodes in graph A? Is this problem in NP(nondeterministic polynomial time)? How is it related to the Hamiltonian cycle problem? Construct your example in python. Input: Graph A as either an edge list or adjacent list. Output: Yes or No. If the output is yes, display the cycle as a sequence of nodes.
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈...
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈ V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v). (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v ∈...
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a...
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a minimum weight spanning tree in G where is not a leaf (a leaf node has degree one). Can you solve this problem in polynomial time? Please write the proof.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT