Jobs
Interviews

Solve Transitive Closure of a Graph using JavaScript Language

Solve Transitive Closure of a Graph using JavaScript to enhance your skills with javascript coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Transitive Closure of a Graph

Difficulty : Medium

Categories :

  • Graphs
  • Dynamic programming

Given a directed graph represented as an adjacency matrix with N vertices, find its transitive closure. The transitive closure is a reachability matrix where matrix[i][j] indicates whether vertex j is reachable from vertex i through a path.

Constraints:

  • 1 ≤ N ≤ 100
  • Graph is represented as NxN adjacency matrix
  • Matrix values are either 0 or 1

Examples:

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: Output[i][j] = 1 if vertex j is reachable from vertex i
Input:
N = 3
graph = [
  [1,0,0],
  [0,1,0],
  [0,0,1]
]
Output: [
  [1,0,0],
  [0,1,0],
  [0,0,1]
]
Explanation: Each vertex can only reach itself

Problem Solving

Input

What You'll Find Here

Hands-On Exercises Work on coding problems inspired by real-world scenarios.

Detailed Explanations Break down complex solutions into easy-to-understand steps.

Interactive Learning Test your skills in an engaging and fun way.

Choose from the following categories