Presenter adjacency lists
Adjacency list is a collection of unordered lists used to represent a finite graph. Each unordered list within an adjacency list describes the set of neighbors of a particular vertex in the graph.
Import
import {presenterAdjacencyLists} from "@raikuxq/alg-ds/lib/exports/algorithms";
API reference
API: /api/algorithms/graph/presenter-adjacency-lists
Example usage
import {presenterAdjacencyLists} from "@raikuxq/alg-ds/lib/exports/algorithms";
import {DirectedGraph} from "@raikuxq/alg-ds/lib/exports/data-structures";
const graph: IGraph<number> = new UndirectedGraph();
graph
.addVertex(1)
.addVertex(2)
.addVertex(3)
.addVertex(4)
.addEdge(1, 2)
.addEdge(1, 3)
.addEdge(3, 4);
const list = presenterAdjacencyLists(graph);
/**
list:
1 => [2, 3]
2 => [1]
3 => [1, 4]
4 => [3]
*/