Similar Problems

Similar Problems not available

Detect Cycle in a Directed Graph - Leetcode Solution

LeetCode:  Detect Cycle in a Directed Graph Leetcode Solution

Difficulty: Unknown

Topics: graphs  

Problem Statement

Given the directed, connected and unweighted graph G and the task to check whether the graph contains a cycle or not.

Example Input

Expected Output

No

Approach

The approach is to use Depth First Traversal to detect a cycle in a Graph. While traversing through the graph if previous node visited node is encountered again this means cycle is present. If cycle is present then print “Yes” otherwise “No”.

Detect Cycle in a Directed Graph Solution Code

1