namastey-unweighted-graph
v1.0.0
Published
A JavaScript package for implementing an Unweighted Graph data structure, ideal for various graph algorithms and data handling needs.
Downloads
5
Maintainers
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');