Transitive Closure of Directed Graph Problem Statement
Given a directed graph with 'V' vertices and 'E' edges, determine if a vertex i
is reachable from vertex j
for all pairs of vertices (i, j)
. A vertex j
is considered reachable from vertex i
if there is a path from i
to j
.
Input:
The input begins with an integer 'T', the number of test cases.
For each test case, the first line contains two space-separated integers 'V' and 'E'.
Following this, each of the next 'E' lines contains two space-separated integers 'a' and 'b', indicating a directed edge from vertex 'a' to vertex 'b'.
Output:
Produce a V x V matrix for each test case, showing reachability between each pair of vertices.
Example:
Input:
1
4 4
0 1
1 2
2 3
3 0
Output:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Constraints:
1 <= T <= 50
1 <= V <= 1000
0 <= E <= 1000
- Time Limit: 1 sec
Note:
The graph edges are one-way (directed).
Each vertex is reachable from itself.
No self-loops or duplicate edges exist.
Graph might have disconnected components.

AnswerBot
4mo
Determine reachability between all pairs of vertices in a directed graph.
Use Floyd Warshall algorithm to find transitive closure of the graph.
Initialize a V x V matrix with 1s on the diagonal and 0s e...read more
Help your peers!
Add answer anonymously...
Goldman Sachs Software Developer interview questions & answers
A Software Developer was asked 2mo agoQ. Given a sorted array, find the number of times a specific element appears in the...read more
A Software Developer was asked 2mo agoQ. Given an array, remove elements that appear consecutively for more than k times....read more
A Software Developer was asked 12mo agoQ. What is the difference between OOP and POP?
Popular interview questions of Software Developer
A Software Developer was asked 2mo agoQ1. Given an array, remove elements that appear consecutively for more than k times....read more
A Software Developer was asked 12mo agoQ2. What is the difference between OOP and POP?
A Software Developer was asked Q3. Write a function to select a pivot element randomly in Quick Sort.
>
Goldman Sachs Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

