Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

namastey-unweighted-graph

A JavaScript package for implementing an Unweighted Graph data structure, ideal for various graph algorithms and data handling needs.

graph, unweighted graph, data structure, algorithm, JavaScript

readme

namastey-unweighted-graph

A package implementing an Unweighted Graph data structure.

Features

  • addVertex(vertex): Adds a vertex to the graph.
  • addEdge(vertex1, vertex2): Adds an edge between two vertices.
  • removeVertex(vertex): Removes a vertex and its associated edges.
  • removeEdge(vertex1, vertex2): Removes an edge between two vertices.
  • dfs(startVertex): Performs a Depth-First Search starting from a given vertex.
  • bfs(startVertex): Performs a Breadth-First Search starting from a given vertex.

Installation

To install the package globally, run:

npm install -g namastey-unweighted-graph

Example

const Graph = require('namastey-unweighted-graph');

const graph = new Graph();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
console.log(graph.dfs('A')); // Output: [ 'A', 'B' ]
console.log(graph.bfs('A')); // Output: [ 'A', 'B' ]
graph.removeEdge('A', 'B');
graph.removeVertex('A');