Cycle Detection in Directed Graph
📖 Scenario: Imagine you are building a task scheduler that runs tasks in order. Each task can depend on other tasks. To make sure the scheduler works correctly, you need to check if there is a cycle in the task dependencies. A cycle means some tasks depend on each other in a loop, which makes scheduling impossible.
🎯 Goal: You will create a program that detects if there is a cycle in a directed graph representing task dependencies. The graph is given as an adjacency list. You will use depth-first search (DFS) with recursion to find cycles.
📋 What You'll Learn
Create a directed graph as an adjacency list using a TypeScript object.
Create a helper array to track visited nodes and recursion stack.
Implement a recursive function to detect cycles using DFS.
Print whether the graph contains a cycle or not.
💡 Why This Matters
🌍 Real World
Cycle detection is important in task scheduling, detecting deadlocks, and verifying dependencies in software projects.
💼 Career
Understanding cycle detection helps in roles like software developer, system engineer, and data scientist where graph algorithms are used.
Progress0 / 4 steps