• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 18, 2023 |1.7K Views
PROBLEM OF THE DAY: 17/10/2023 | Transitive closure of a Graph
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Jay Dalsaniya. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Graph but will also help you build up problem-solving skills.

In this problem, we are given, a directed graph, to determine whether a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Here, vertex j is reachable from another vertex i means that there is a path from vertex i to j. The reachability matrix is called the transitive closure of a graph. The directed graph is represented by an adjacency matrix where there are N vertices.

Example :

Input: N = 4
graph = {{1, 1, 0, 1}, 
        {0, 1, 1, 0}, 
        {0, 0, 1, 1}, 
        {0, 0, 0, 1}}

Output: {{1, 1, 1, 1}, 
        {0, 1, 1, 1}, 
        {0, 0, 1, 1}, 
        {0, 0, 0, 1}}

Explanation: 
The output list shows the reachable indexes.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/transitive-closure-of-a-graph0930/1