14. Cycle Detection in Undirected Graph using DFS
Medium

Problem Statement

Detect whether there is a cycle in an undirected graph using Depth First Search (DFS).

Examples

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

Sign in to Run Code and Submit