datavis-tech / graph-data-structure

A graph data structure with topological sort and shortest path algorithms.
MIT License
249 stars 46 forks source link

Detect cycles #32

Closed thiagodp closed 3 years ago

thiagodp commented 4 years ago

Add methods for cycles:

/** Indicates whether the graph has cycles. */
hasCycles(): boolean;
/** Returns a matrix with any cycles found, such as [ [ "a, "b", "a", ], [ "a", "b", "c", "a" ] ] */
cycles(): Array< Array< string > >;

DFS could be adapted for that purpose.

curran commented 4 years ago

Very cool idea!

PRs welcome :)

curran commented 3 years ago

Done in https://github.com/datavis-tech/graph-data-structure/pull/42/files