Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pls use c++ In this problem, you need to implement the greedy algorithm (discussed in the class) to solve the interval scheduling problem, where a

pls use c++

In this problem, you need to implement the greedy algorithm (discussed in the class) to solve the interval scheduling problem, where a set of n intervals (s(i), f (i)), 1 i n is given and the problem is to find the maximum subset of non-overlapping intervals. For this,

Step 1. implement the following function prototype: bool * IntervalScheduling(int *s, int *f, int n): it takes the pointer to arrays s and f containing start and finish time of n intervals, and solves the interval scheduling problem and returns the output as a pointer to a boolean array, say output, where output[i] is true if interval i has been accepted, otherwise false.

Step 2.

In the main function, read the input from a file input-scheduling.txt which has the following format:

6

1 4

5 9

2 5

3 5

1 3

4 8

The first line denote the number n of intervals in the instance, second line denote the start and finish time of interval 1, and so on.

Step 3. For example, your answer in case of above input instance should be: 2, 4, 5

Call the function IntervalScheduling with the input read in the previous step, and take its output in a boolean array output. Then print the accepted intervals to the user.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions