Transpose directed graph
Transposed graph is another directed graph on the same set of vertices with all of the edges reversed compared to the orientation of the corresponding edges in G
Import
import {transposeDirectedGraph} from "@raikuxq/alg-ds/lib/exports/algorithms";
API reference
API: /api/algorithms/graph/transpose-directed-graph
Example usage
import {transposeDirectedGraph} from "@raikuxq/alg-ds/lib/exports/algorithms";
import {DirectedGraph} from "@raikuxq/alg-ds/lib/exports/data-structures";
const sourceGraph = new DirectedGraph();
/**
* Source graph
*
* * V1 V2 V3 V4
* V1 0 1 0 1
* V2 0 0 0 0
* V3 0 0 0 1
* V4 0 0 0 0
*/
sourceGraph
.addVertex("Vertex_1")
.addVertex("Vertex_2")
.addVertex("Vertex_3")
.addVertex("Vertex_4")
.addEdge("Vertex_1", "Vertex_2")
.addEdge("Vertex_1", "Vertex_4")
.addEdge("Vertex_3", "Vertex_4");
/**
* Transposed graph
*
* * V1 V2 V3 V4
* V1 0 0 0 0
* V2 1 0 0 0
* V3 0 0 0 0
* V4 1 0 1 0
*/
const transposedGraph = transposeDirectedGraph(sourceGraph);