0% found this document useful (0 votes)
4 views8 pages

Lec 16

The Activity Selection Problem involves selecting the maximum number of mutually compatible activities from a given set, defined by their start and finish times. A greedy algorithm is used to solve this problem by always choosing the activity that finishes the earliest and is compatible with previously selected activities, resulting in a time complexity of O(n log n). Applications of this problem include scheduling, resource allocation, and event planning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Lec 16

The Activity Selection Problem involves selecting the maximum number of mutually compatible activities from a given set, defined by their start and finish times. A greedy algorithm is used to solve this problem by always choosing the activity that finishes the earliest and is compatible with previously selected activities, resulting in a time complexity of O(n log n). Applications of this problem include scheduling, resource allocation, and event planning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Analysis of Algorithm

Lec 16
Activity Selection
• The Activity Selection Problem is a classic problem
in combinatorial optimization that deals with selecting
the maximum number of mutually compatible activities
from a given set of activities. Each activity has a defined
start time and end time, and two activities are
compatible if they do not overlap in time.
Problem Description
• Input:
A list of activities, where each activity is represented as
a pair (si,fi) where:
• si​: The start time of the activity.
• fi​: The finish time of the activity.
• Output:
The maximum number of activities that can be selected,
such that no two selected activities overlap.
Approach (Greedy Algorithm)
• The problem can be efficiently solved using a greedy
algorithm. The idea is to always choose the activity
that finishes the earliest and is compatible with the
previously selected activity.
Steps for the Greedy Algorithm
• Sort the activities based on their finish times (fif_ifi​)
in ascending order.
• Select the first activity (the one that finishes earliest).
• For each subsequent activity
• Check if the start time (si​) of the current activity is
greater than or equal to the finish time (flast​) of the last
selected activity.
• If yes, select the activity and update flast​.
• Continue until all activities have been considered.
Example
• Activities: (s,f):
• (1,4),(3,5),(0,6),(5,7),(3,8),(5,9),(6,10),(8,11),(8,12),
(2,13),(12,14)
• Output:
• Selected Activities
• (1,4),(5,7),(8,11),(12,14)
Time Complexity
• Sorting the activities: O(nlog⁡n)
• Selecting activities: O(n)
• Total Time Complexity: O(nlog⁡n)
Applications

•Scheduling problems (e.g., job scheduling, conference room allocation).


•Resource allocation in distributed systems.
•Event planning to maximize participation.

You might also like