Detect Cycles in a Directed Graph using DFS
During the DFS traversal, we can keep track of the visited nodes and the current path. If we encounter a node that has already been visited and is still on the current path, then we have detected a cycle.
function isCyclic(adj:number[][], v:number){
...
sumanmanna.hashnode.dev2 min read