Detect a cycle in a directed graph.
Unlock detailed company stats for this questionUpgrade
Implemented with DFS. Follow-up: optimize for a stream of edges, where each newly added edge must be checked for whether it creates a cycle (Union-Find with path compression).
Expect follow-ups like
- Return the topological order.
Format · Approach only; no code required.
Also asked as · Detect a cycle in an undirected graph.; Check for a cycle in a directed graph.
Community answers
No answers contributed by the community yet.
Related questions
Detect cycle in graphFind the shortest cycle in a directed acyclic graph.Encode and decode a DAG (directed acyclic graph).Related courses

Course

Course
Course


