Question: Question 3 : There are n activities with their start and finish times. We write the following pseudocode so that a machine can perform a
Question : There are activities with their start and finish times. We write the following
pseudocode so that a machine can perform a maximum number of activities. Assume that the
machine can do only a single activity at a time. Here is an sample inputoutput:
Input: start finish
Output:
Explanation: A person can perform at most two activities. The
maximum set of activities that can be executed
is These are indexes in start and finish
Input: start finish ;
Output:
Explanation: A person can perform at most four activities. The
maximum set of activities that can be executed
is These are indexes in start and finish
Sort activities according to their finishing time
Select the first activity from the sorted array and print
For each remaining activity in the sorted array
If the start time of the current activity is greater than or equal to the finish time
of the previously selected activity
Select this activity and print it
endlf
endFor
Is it a greedy algorithm? If yes, justify your answer. If no what kind of problemsolving
approach best describes this pseudocode? Also, what is the time complexity of this
pseudocode?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
