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 3: There are n 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 input/output:
Input: start[]={10,12,20}, finish []={20,25,30}
Output: 02
Explanation: A person can perform at most two activities. The
maximum set of activities that can be executed
is {0,2}[ These are indexes in start[] and finish[]]
Input: start[]={1,3,0,5,8,5}, finish []={2,4,6,7,9,9};
Output: 0134
Explanation: A person can perform at most four activities. The
maximum set of activities that can be executed
is {0,1,3,4}[ These are indexes in start [] and finish[]
Sort activities according to their finishing time
Select the first activity from the sorted array and print t??
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 problem-solving
approach best describes this pseudocode? Also, what is the time complexity of this
pseudocode?
 Question 3: There are n activities with their start and finish

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!