cycle-test

1.0.3 • Public • Published

cycle-test

cycle-test detects cycles in your directed graph by returning true or false.

Status:

Version: 1.0.0

This is beta software.

Installation:

npm install cycle-test

Use:

Each value of the input array represents a vertex identified by its array index. Each vertex must be undefined (ignored) or an array of zero or more integers, each representing an edge to another vertex.

ct = require('cycle-test');

graph = [[1], [2], [0]];
console.log(ct.hasCycle(graph));
// true

graph = [[1, 2], [2], []];
console.log(ct.hasCycle(graph));
// false

graph = [[0]];
console.log(ct.hasCycle(graph));
// true

graph = [[1], [3], , [0]];
console.log(ct.hasCycle(graph));
// true

Explanation:

For an explanation of the algorithm, see the following stackoverflow comment and GeeksforGeeks article.

Authors:

Andrew Engelbrecht (lead developer and maintainer)

License:

cycle-test is realeased under CC0. (CC0 License)

Package Sidebar

Install

npm i cycle-test

Weekly Downloads

5

Version

1.0.3

License

CC0-1.0

Unpacked Size

13.4 kB

Total Files

5

Last publish

Collaborators

  • sudoman