Cycle Detection in Directed Graph (DFS)

BFS & DFS Problems DSA practice problem on Onlearn.

Difficulty: hard.

Topics: Detect Cycle in a Directed Graph, Directed Graph, Graph, Depth-First Search, Graph Traversal, Adjacency List, Time Complexity, Space Complexity, Recursion, Arrays, visited tracking, dfs, graph properties, cycle detection, time complexity analysis, Graph Traversal Utilities.

"""Problem Statement: You are given a directed graph with V vertices, labeled from 0 to V 1, and E edges. Your task is to determine if the graph contains any cycle. A cycle exists if there is a path from a vertex back to itself. Input Specification: The first line contains two integers, V and E, representing the number of vertices and edges, respectively. The following E lines each contain two integers, u and v, denoting a directed edge from vertex u to vertex v. Output Specification: Print "True" if the graph contains at least one cycle, and "False" otherwise. Sample Test Cases: Example 1: Input: 11 11 1 2 2 3 3 4 3 7 4 5 5 6 7 5 8 9 9 10 10 8 Output: True Explanation: The cycle is 8 9 10 8. Example 2: Input: 11 10 1 2 2 3 3 4 3 7 4 5 5 6 7 5 8 9 9 10 Output: False Explanation: No cycle detected in the given graph."""