A Graph structure is useful for modeling relationships and connections between multiple entities. They consist of a set of vertices (also known as nodes) and edges, which connect the vertices together.

Example

const graph = new Graph(5);
graph.addEdge(0, 1, 2);
graph.addEdge(1, 2, 3);
graph.addEdge(2, 3, 4);

graph.getWeight(0, 1); // 2
graph.getNeighbors(1); // [0, 2]
graph.getAllEdges(); // [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
graph.getAllNodes(); // [0, 1, 2, 3]

Hierarchy

  • Graph

Constructors

Properties

defaultWeight: number
weightMatrix: number[][]

Methods

  • Parameters

    • source: number
    • destination: number
    • weight: number

    Returns void

  • Parameters

    • source: number
    • destination: number

    Returns number

  • Parameters

    • source: number
    • destination: number

    Returns boolean

  • Parameters

    • source: number
    • destination: number

    Returns void

Generated using TypeDoc