Detect Cycle in a Directed Graph - Coddicted

Detect Cycle in a Directed Graph 1

Title: Detect Cycle in a Directed Graph Source: www.geeksforgeeks.org

Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false. For example, the following graph contains three cycles 0->2->0, 0->1->2->0 and 3->3, so your function must return true.

Java solution


Back To Top
Rate this post

One comment on “Detect Cycle in a Directed Graph

  1. Reply chaitrali Aug 9,2016 9:40 am

    Thanks for this solution. But I dont find any use of keeping visited array. Because even if it is visited for some node it might be required for other node to check the cycle. Please provide any use case where it is useful to have visited array. show any such graph. Thank you!

Leave a Reply