How to use Greedy algorithm for activity selection problem?

To use Greedy algorithm for activity selection problem, sort activities by finish time and select the ones with earliest finish time.

The activity selection problem involves selecting a maximum number of non-overlapping activities from a set of activities, each with a start time and finish time. The goal is to maximize the number of activities that can be completed.

The Greedy algorithm for activity selection involves sorting the activities by their finish time and selecting the activities with the earliest finish time. This ensures that the maximum number of activities can be completed without overlapping.

To implement the Greedy algorithm, first sort the activities by their finish time in ascending order. Then, select the first activity with the earliest finish time. Next, select the next activity with the earliest finish time that does not overlap with the previously selected activity. Repeat this process until no more activities can be selected.

For example, consider the following set of activities:

Activity 1: Start time = 1, Finish time = 4
Activity 2: Start time = 3, Finish time = 5
Activity 3: Start time = 0, Finish time = 6
Activity 4: Start time = 5, Finish time = 7
Activity 5: Start time = 3, Finish time = 8
Activity 6: Start time = 5, Finish time = 9
Activity 7: Start time = 6, Finish time = 10
Activity 8: Start time = 8, Finish time = 11

Sorting the activities by finish time gives:

Activity 3: Start time = 0, Finish time = 6
Activity 1: Start time = 1, Finish time = 4
Activity 2: Start time = 3, Finish time = 5
Activity 5: Start time = 3, Finish time = 8
Activity 4: Start time = 5, Finish time = 7
Activity 6: Start time = 5, Finish time = 9
Activity 7: Start time = 6, Finish time = 10
Activity 8: Start time = 8, Finish time = 11

Selecting the first activity with the earliest finish time, Activity 1, gives:

Activity 1: Start time = 1, Finish time = 4

Next, select the next activity with the earliest finish time that does not overlap with Activity 1. This is Activity

Study and Practice for Free

Trusted by 100,000+ Students Worldwide

Achieve Top Grades in your Exams with our Free Resources.

Practice Questions, Study Notes, and Past Exam Papers for all Subjects!

Need help from an expert?

4.93/5 based on525 reviews

The world’s top online tutoring provider trusted by students, parents, and schools globally.

Related Maths a-level Answers

    Read All Answers
    Loading...