Chapter 5: Greedy Algorithms
Activity 11: The Interval Scheduling Problem
In this activity, we will find the optimal scheduling of tasks to maximize the number of tasks that can be completed. Follow these steps to complete the activity:
- Add the required header files and define the
Task
struct as follows:#include <list> #include <algorithm> #include <iostream> #include <random> // Every task is represented as a pair <start_time, end_time> struct Task { unsigned ID; unsigned start_time; unsigned end_time; };
- The following function can be used to generate a list of N tasks with random data:
auto initialize_tasks(size_t num_tasks) { std::random_device rd; std::mt19937 rand(rd()); std::uniform_int_distribution<std::mt19937::result_type> uniform_dist(1, num_tasks); // Create...