Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rtsao/scc
Find strongly connected components of a directed graph using Tarjan's algorithm
https://github.com/rtsao/scc
cycle-detection strongly-connected-components tarjan topological-sort
Last synced: 2 months ago
JSON representation
Find strongly connected components of a directed graph using Tarjan's algorithm
- Host: GitHub
- URL: https://github.com/rtsao/scc
- Owner: rtsao
- License: mit
- Created: 2019-04-15T16:38:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-06T17:07:00.000Z (over 2 years ago)
- Last Synced: 2024-10-15T02:27:05.702Z (2 months ago)
- Topics: cycle-detection, strongly-connected-components, tarjan, topological-sort
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `@rtsao/scc`
Find strongly connected components of a directed graph using [Tarjan's algorithm](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm).
This algorithm efficiently yields both a topological order and list of any cycles.
## Installation
```
yarn add @rtsao/scc
``````
npm install @rtsao/scc
```## Usage
```js
const scc = require("@rtsao/scc");const digraph = new Map([
["a", new Set(["c", "d"])],
["b", new Set(["a"])],
["c", new Set(["b"])],
["d", new Set(["e"])],
["e", new Set()]
]);const components = scc(digraph);
// [ Set { 'e' }, Set { 'd' }, Set { 'b', 'c', 'a' } ]
```#### Illustration of example input digraph
```
┌───┐ ┌───┐
│ d │ ◀── │ a │ ◀┐
└───┘ └───┘ │
│ │ │
▼ ▼ │
┌───┐ ┌───┐ │
│ e │ │ c │ │
└───┘ └───┘ │
│ │
▼ │
┌───┐ │
│ b │ ─┘
└───┘
```