Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

namastey-graph

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

namastey-graph

A package implementing Graph data structure

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

namastey-graph

namastey-graph is a JavaScript package that implements the Graph data structure along with various important methods like adding/removing vertices and edges, depth-first search (DFS), and breadth-first search (BFS).

Features

  • addVertex(vertex): Adds a vertex to the graph.
  • addEdge(vertex1, vertex2): Adds an edge between two vertices.
  • removeEdge(vertex1, vertex2): Removes the edge between two vertices.
  • removeVertex(vertex): Removes a vertex and all associated edges.
  • depthFirstSearch(start): Performs depth-first search starting from a given vertex.
  • breadthFirstSearch(start): Performs breadth-first search starting from a given vertex.
  • printGraph(): Prints the graph's adjacency list.

Installation

To install the package globally, run the following command:

npm install -g namastey-graph

Examples

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

const graph = new Graph();
graph.addVertex('A');
graph.addVertex('B');
graph.addVertex('C');
graph.addEdge('A', 'B');
graph.addEdge('A', 'C');
graph.addEdge('B', 'C');

graph.printGraph();
// Output:
// A -> B, C
// B -> A, C
// C -> A, B

const dfsResult = graph.depthFirstSearch('A');
console.log('DFS:', dfsResult);
// Output: DFS: [ 'A', 'B', 'C' ]

const bfsResult = graph.breadthFirstSearch('A');
console.log('BFS:', bfsResult);
// Output: BFS: [ 'A', 'B', 'C' ]

Keywords

FAQs

Package last updated on 27 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc