Question: my preferred language is python or c the question is...
My preferred language is Python or C++. The question is essentially the greedy algorithm, however it starts from the end as opposed to from the beginning. In other words, instead of selecting the earliest activity to finish, we instead select the last activity that finishes, and work backwards from there.
Please ensure that the solution follows the specifications given below and matches the sample solution. Other answers on Zookal did not follow these specifications.
Suppose that instead of always selecting the first activity to finish, we instead select the last activity to start that is compatible with all previously selected activities.
Include a verbal description of your algorithm, pseudocode and analysis of the theoretical running time. The program should read input from a file named “act.txt”. The file contains lists of activity sets with number of activities in the set in the first line followed by lines containing the activity number, start time & finish time.
1 1 4
2 3 5
3 0 6
4 5 7
5 3 9
6 5 9
7 6 10
8 8 11
9 8 12
10 2 14
11 12 16
3 6 8
1 7 9
2 1 2
In the above example the first activity set contains 11 activities with activity 1 starting at time 1 and finishing at time 4, activity 2 starting at time 3 and finishing at time 5, etc.. The second activity set contains 3 activities with activity 3 starting at time 6 and finishing at time 8 etc. The activities in the file are not in any sorted order.
Your results including the number of activities selected and their order should be outputted to the terminal. For the above example the results are:
Number of activities selected = 4
Activities: 2 4 9 11
Number of activities selected = 2
Activities: 2 1
Note: There is an alternative optimal solution for Set 1. Since activities 8 and 9 have the same start time of 8, 2 4 8 11 would be an alternative solution. Your program only needs to find one of the optimal solutions. For either solution the activities differ from the solution presented in the text which uses the earliest-finish time criteria.