Detecting Cycles in a Directed Graph Using Depth-First Search (DFS) How to detect a cycle in a directed graph using DFS?