Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started