Transitive Closure of a Graph using DFS
The transitive closure of a directed graph represents all the possible paths between any two vertices in the graph. It is a new graph that has the same vertices as the original graph, but includes all possible edges that can be formed by following a path in the original graph.

The transitive closure of a graph can be found using Depth-First Search (DFS) algorithm. Here are the steps to find the transitive closure of a graph using DFS:
Initialize a matrix of size N x N, where N is the number of vertices in the graph. This matrix will represent the transitive closure of the graph.
For each vertex v in the graph, perform a DFS starting at v. During the DFS, mark all vertices that are reachable from v.
Once the DFS is complete, update the matrix to include all the edges that can be formed by following a path from v to each of the reachable vertices. Specifically, if vertex i is reachable from vertex j during the DFS, mark the entry (j,i) in the matrix.
Repeat step 2 and 3 for all vertices in the graph.
The resulting matrix represents the transitive closure of the graph.
Program List
-
1) Transitive closure of a graph using dfs in java
2) Transitive closure of a graph using dfs in c++
3) Transitive closure of a graph using dfs in c
4) Transitive closure of a graph using dfs in c#
5) Transitive closure of a graph using dfs in php
6) Transitive closure of a graph using dfs in python
7) Transitive closure of a graph using dfs in ruby
8) Transitive closure of a graph using dfs in scala
9) Transitive closure of a graph using dfs in swift
10) Transitive closure of a graph using dfs in kotlin
11) Transitive closure of a graph using dfs in typescript
12) Transitive closure of a graph using dfs in golang
13) Transitive closure of a graph using dfs in vb.net
14) Transitive closure of a graph using dfs in node js
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment