Closed notmatthancock closed 3 years ago
I agree an error should be thrown.
A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG).
From https://en.wikipedia.org/wiki/Topological_sorting
I wonder what sort of change this would take...
It seems the depth first function could be slightly modified to be in accordance with the method shown on wiki so that it throws an Error on a detected cycle -- maybe only if a errorOnCycle
flag is passed to depthFirstSearch
?
Got it. That would be a welcome change!
Cool, I'll take a whack at it.
Performing a topological sort on a graph with cycles should throw an error (related: https://github.com/datavis-tech/graph-data-structure/issues/32).
Currently, you can do: