Hierarchy

  • Graph

Implements

  • IGraph

Methods

  • Add edge between 2 existing vertices

    Returns

    self reference

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b");

    // or


    const g = new Graph(false, true);
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b", 5);

    Parameters

    • u: string
    • v: string
    • w: number = 1

      only pass a value if the isWeighted flag is true

    Returns Graph

  • Add a new vertex to the graph

    Returns

    self reference

    Example

    const g = new Graph();

    g.addVertex("a").addVertex("b");

    Parameters

    • vertex: string

    Returns Graph

  • retrieve the neighbors of a vertex

    Returns

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b");

    g.getNeighbors("a"); // {b:1}

    Parameters

    • vertex: string

    Returns {
        [key: string]: number;
    }

    • [key: string]: number
  • Get the current number of vertices in the graph

    Returns

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");

    g.getVerticesNumbers(); //2

    Returns number

  • Remove edge between 2 vertices if the graph is directional it will remove 1 way

    Returns

    self reference

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b");

    g.removeEdge("a", "b")

    Parameters

    • u: string
    • v: string

    Returns Graph

  • Remove a vertex from the graph with all of it's links with other vertices

    Returns

    self reference

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b");

    g.removeVertex("a");

    Parameters

    • vertex: string

    Returns Graph

  • Prints a visual representation of the graph

    Returns

    Example

    const g = new Graph();
    g.addVertex("a").addVertex("b");
    g.addEdge("a", "b");

    g.view();

    // a => [b, 1] :
    // b => [a, 1] :

    Returns Graph

Generated using TypeDoc