![]() |
VOOZH | about |
Given an unweighted directed graph G as a path matrix, the task is to find out if the graph is Strongly Connected or Unilaterally Connected or Weakly Connected.
- Strongly Connected: A graph is said to be strongly connected if every pair of vertices(u, v) in the graph contains a path between each other. In an unweighted directed graph G, every pair of vertices u and v should have a path in each direction between them i.e., bidirectional path. The elements of the path matrix of such a graph will contain all 1's.
- Unilaterally Connected: A graph is said to be unilaterally connected 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. Hence, at least for any pair of vertices, one vertex should be reachable form the other. Such a path matrix would rather have upper triangle elements containing 1's OR lower triangle elements containing 1's.
- Weakly Connected: A directed graph is weakly connected if there is a path between every two vertices in the underlying undirected graph (i.e, the graph formed when the direction of the edges are removed).
Examples:
Input: Below is the given graph with path matrix:
Output: Strongly Connected Graph
Input: Below is the given graph with path matrix:
Output: Unilaterally Connected Graph
Input: Below is the given graph with path matrix:
Output: Weakly Connected Graph
Approach:
Below is the implementation of the above approach:
Unilaterally Connected
Time Complexity: O(N2)
Auxiliary Space: O(1)