0% found this document useful (0 votes)
3 views11 pages

Activity Selection Problem DP

The document discusses the Activity Selection Problem, which aims to find the maximum number of non-overlapping activities that can be performed by a single person. It presents a dynamic programming approach to solve this problem, contrasting it with a previously discussed greedy algorithm. The document also includes an example of input and output activities, along with a note on the time complexity of the solution.

Uploaded by

shanicrazyf
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)
3 views11 pages

Activity Selection Problem DP

The document discusses the Activity Selection Problem, which aims to find the maximum number of non-overlapping activities that can be performed by a single person. It presents a dynamic programming approach to solve this problem, contrasting it with a previously discussed greedy algorithm. The document also includes an example of input and output activities, along with a note on the time complexity of the solution.

Uploaded by

shanicrazyf
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/ 11

Design and Analysis of

Algorithm
Muhammad Umer Mehmood
Activity Selection Problem

Using Dynamic Programming


Introduction
• Given a set of activities and the starting and finishing time of each
activity,
• find 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.
Introduction
For Example:
Input:
{1,4}, {3,5}, {0,6}, {5,7}, {3,8}, {5,9}, {6,10}, {8,11}, {8,12}, {2,13}, {12,14}

Output:
{1,4}, {5,7}, {8,11}, {12,14}
In Previous Lecture (Greedy
Algorithm)
• We discussed the greedy approach to the activity selection problem.

• We will discuss a dynamic programming solution for the activity


selection problem.

• Variation of the Longest Increasing Subsequence (LIS) problem.


Example
• The idea is first to sort a given set of activities in increasing order of
their start time.

• Let jobs be the sorted array of activities.

• Define array A by itself is an array that store maximum non-


conflecting jobs ending at job.
Example
Example
• For example, consider the following sorted activities:

• {0,6}, {1,4}, {2,13}, {3,5}, {3,8}, {5,7}, {5,9}, {6,10}, {8,11}, {8,12},
{12,14},
Example
would be:
Time Complexity
• The time complexity of the above solution is and require extra space,
where n is the total number of given activities.
i 1 2 3 4 5 6 7 8 9 10 11

1 3 0 5 3 5 6 8 8 2 12

4 5 6 7 9 9 10 11 12 14 16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy