16. Cycle Detection In Directed Graph Using DFS
Medium

Problem Statement

Given a Directed Graph with V vertices and E edges, check whether it contains any cycle or not.

Examples

1Example 1
Input:
{ "V": 4, "adj": [ [ 1 ], [ 2 ], [ 3 ], [ 1 ] ] }
Output:
true
2Example 2
Input:
{ "V": 3, "adj": [ [ 1 ], [ 2 ], [] ] }
Output:
false
3Example 3
Input:
{ "V": 5, "adj": [ [ 1 ], [ 2 ], [ 3, 4 ], [ 1 ], [] ] }
Output:
true
Loading...

Sign in to Run Code and Submit

    16. Cycle Detection In Directed Graph Using DFS – DSA Problem Solution | DSAPrime