Critical Path Method for Scheduling

Data Pipelines, Monitoring & Reliability DS practice problem on Onlearn.

Difficulty: medium.

Topics: Critical Path Method for Scheduling, Earliest Start Time, Float and Slack Calculation, Topological Sorting, Forward and Backward Pass, Dependency Directed Acyclic Graphs, Operations Research, Distributed Systems, Software Engineering, Graph Theory, Project Management, Network Analysis, Resource Allocation, Task Dependency Modeling, Pipeline Orchestration, Constraint Satisfaction.

Implement the Critical Path Method (CPM) for project scheduling. Given a set of tasks with durations and dependency relationships forming a directed acyclic graph (DAG), compute: 1. Project duration : The minimum total time to complete all tasks. 2. Critical path : The sequence of tasks (in execution order) that determines the project duration. These are tasks with zero slack, meaning any delay in them delays the entire project. 3. Slack : For each task, the amount of time it can be delayed without affecting the project duration. Your function receives: tasks: A dictionary mapping task names (strings) to their durations (integers). dependencies: A dictionary mapping each task name to a list of prerequisite task names that must be completed before it can start. Tasks with no prerequisites have an empty list. The function should return a dictionary with three keys: 'project duration': An integer representing the minimum time to finish all tasks. 'critical path': A list of task names on the critical path, ordered by execution sequence. When multiple tasks have the same topological precedence, use alphabetical ordering. 'slack': A dictionary mapping each task name to its total slack (integer). Assume the input always forms a valid DAG with no cycles.