Contents
- 1 What is the time complexity of activity selection problem?
- 2 How does greedy choice work for activities sorted according to Finishtime?
- 3 What is the difference between Dynamic Programming and greedy method?
- 4 Which is the greedy choice in activity selection?
- 5 How to implement when given given given activity is not sorted?
What is the time complexity of activity selection problem?
We will use the greedy approach to find the next activity whose finish time is minimum among rest activities, and the start time is more than or equal with the finish time of the last selected activity. The complexity of this problem is O(n log n) when the list is not sorted.
What is the time complexity of the algorithm to solve the activity selection problem?
Activity Selection problem is a approach of selecting non-conflicting tasks based on start and end time and can be solved in O(N logN) time using a simple greedy approach. Modifications of this problem are complex and interesting which we will explore as well.
How does greedy choice work for activities sorted according to Finishtime?
How does Greedy Choice work for Activities sorted according to finish time? Let the given set of activities be S = {1, 2, 3, …n} and activities are sorted by finish time. (Note that the activities in B are independent and k has the smallest finishing time among all. Since k is not 1, finish(k) >= finish(1)).
What is the basic characteristics of greedy algorithm?
Greedy Algorithms works step-by-step, and always chooses the steps which provide immediate profit/benefit. It chooses the “locally optimal solution”, without thinking about future consequences. Greedy algorithms may not always lead to the optimal global solution, because it does not consider the entire data.
What is the difference between Dynamic Programming and greedy method?
In a greedy Algorithm, we make whatever choice seems best at the moment in the hope that it will lead to global optimal solution. In Dynamic Programming we make decision at each step considering current problem and solution to previously solved sub problem to calculate optimal solution .
How to select the maximum number of activities?
Select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time. Example 1 : Consider the following 3 activities sorted by by finish time. start [] = {10, 12, 20}; finish [] = {20, 25, 30}; A person can perform at most two activities.
Which is the greedy choice in activity selection?
The greedy choice is to always pick the next activity whose finish time is least among the remaining activities and the start time is more than or equal to the finish time of the previously selected activity. We can sort the activities according to their finishing time so that we always consider the next activity as minimum finishing time activity.
What is the complexity of the activity selection problem?
Time Complexity: It takes O (n log n) time if input activities may not be sorted. It takes O (n) time when it is given that input activities are always sorted. Following Activities should be selected. Activity started at: 1 and ends at 2 Activity started at: 3 and ends at 4 Activity started at: 5 and ends at 7 Activity started at: 8 and ends at 9
How to implement when given given given activity is not sorted?
Let the first activity selected by B be k, then there always exist A = {B – {k}} U {1}. (Note that the activities in B are independent and k has the smallest finishing time among all. Since k is not 1, finish (k) >= finish (1)). How to implement when given activities are not sorted? We create a structure/class for activities.