SlideShare une entreprise Scribd logo
1  sur  12
AN ACTIVITY-SELECTION PROBLEM
BY SUMITA DAS
Created by Sumita Das
An Activity-selection problem
 Suppose we have a set of activities S={a1,a2,….,an} (Total n
activities) that wish to use a common resource which can serve
only one activity at a time.
 Mutually exclusive access to single resource.
 Each activity ai is having start time si and finish time fi, where
0<=si<=fi<∞
 Goal: To find a maximum-size subset of mutually compatible
activities
 Compatible Activities: Activities ai and aj are compatible if si>=fj
or sj>=fi
i.e. Second Activity starts before first activity finishes.
Created by Sumita Das
Let set S consists of following activities which is sorted in
monotonically increasing order of finish time.
k 0 1 2 3 4 5 6 7 8 9 10 11
sk - 1 3 0 5 3 5 6 8 8 2 12
fk 0 4 5 6 7 8 9 10 11 12 14 16
Created by Sumita Das
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
a11
Created by Sumita Das
RECURSIVE-ACTIVITY-SELECTOR( s, f, k, n)
1. m= k +1
2. while m <= n and s[m] < f[k]
3. m=m +1
4. if m <= n
5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR
(s, f, m, n)
6. else return Ø
A Recursive Greedy Algorithm
Created by Sumita Das
s- array of start time of activities
f- array of finish time of activities
k- index of subproblem Sk
Where Sk is the set of activities that start after activity ak
finishes.
n- size of original problem
 Add a fictitious activity a0 with f0=0
 So Subproblem S0 is entire set of activities S.
 Initial call RECURSIVE-ACTIVITY-SELECTOR( s, f, 0,
n) solves the entire problem
Created by Sumita Das
RECURSIVE-ACTIVITY-SELECTOR( s, f, 0, 11)
1. m= k +1
2. while m <= n and s[m] < f[k]
3. m=m +1
4. if m <= n
5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR
(s, f, m, n)
6. else return Ø
k=0 m=0+1=1
1<=11 and s[1]<f[0]
1<=11
1<0 false. While loop exits
Return a1 U RECURSIVE-
ACTIVITY- SELECTOR (s, f,
1, 11)
k 0 1 2 3 4 5 6 7 8 9 10 11
sk - 1 3 0 5 3 5 6 8 8 2 12
fk 0 4 5 6 7 8 9 10 11 12 14 16
Created by Sumita Das
RECURSIVE-ACTIVITY-SELECTOR( s, f, 1, 11)
1. m= k +1
2. while m <= n and s[m] < f[k]
3. m=m +1
4. if m <= n
5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR
(s, f, m, n)
6. else return Ø
k=1 m=1+1=2
2<=11 and s[2]<f[1] 3<4 true
m=2+1=3
3<=11 and s[3]<f[1] 0<4 true
m=3+1=4
4<=11 and s[4]<f[1] 5<4 false. While loop exits4<=11
Return a4 U RECURSIVE-
ACTIVITY- SELECTOR (s, f,
4, 11)
k 0 1 2 3 4 5 6 7 8 9 10 11
sk - 1 3 0 5 3 5 6 8 8 2 12
fk 0 4 5 6 7 8 9 10 11 12 14 16
Created by Sumita Das
RECURSIVE-ACTIVITY-SELECTOR( s, f, 4, 11)
1. m= k +1
2. while m <= n and s[m] < f[k]
3. m=m +1
4. if m <= n
5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR
(s, f, m, n)
6. else return Ø
k=4 m=4+1=5
5<=11 and s[5]<f[4] 3<7 true
m=5+1=6
6<=11 and s[6]<f[4] 5<7 true
m=6+1=7
7<=11 and s[7]<f[4] 6<7 true
m=7+1=8
8<=11 and
s[8]<f[4] 8<7 false.While loop exits8<=11
Return a8 U RECURSIVE-
ACTIVITY- SELECTOR (s, f,
8, 11)
k 0 1 2 3 4 5 6 7 8 9 10 11
sk - 1 3 0 5 3 5 6 8 8 2 12
fk 0 4 5 6 7 8 9 10 11 12 14 16
Created by Sumita Das
RECURSIVE-ACTIVITY-SELECTOR( s, f, 8, 11)
1. m= k +1
2. while m <= n and s[m] < f[k]
3. m=m +1
4. if m <= n
5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR
(s, f, m, n)
6. else return Ø
k=8 m=8+1=9
9<=11 and s[9]<f[8] 8<11 true
m=9+1=10
10<=11 and s[10]<f[8] 2<11 true
m=10+1=11
11<=11 and s[11]<f[8] 12<11 falseWhile
loop exits
11<=11
Return a11 U RECURSIVE-
ACTIVITY- SELECTOR (s, f,
11, 11)
k 0 1 2 3 4 5 6 7 8 9 10 11
sk - 1 3 0 5 3 5 6 8 8 2 12
fk 0 4 5 6 7 8 9 10 11 12 14 16
Created by Sumita Das
 RECURSIVE-ACTIVITY- SELECTOR (s, f, 11, 11)
returns Ø.
 Resulting set of selected activities is {a1, a4 a8, a11}
Created by Sumita Das
References
 Introduction to Algorithms 2nd ,Cormen, Leiserson,
Rivest and Stein, The MIT Press, 2001.
 Introduction to Design & Analysis Computer Algorithm
3rd, Sara Baase, Allen Van Gelder, Adison-Wesley, 2000.
Created by Sumita Das

Contenu connexe

Plus de Sumita Das

Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection methodSumita Das
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous searchSumita Das
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problemsSumita Das
 
Loop alignment
Loop alignmentLoop alignment
Loop alignmentSumita Das
 
Maps in android
Maps in androidMaps in android
Maps in androidSumita Das
 
Hardware and software parallelism
Hardware and software parallelismHardware and software parallelism
Hardware and software parallelismSumita Das
 
Trusted systems1
Trusted systems1Trusted systems1
Trusted systems1Sumita Das
 
Multiprotocol label switching
Multiprotocol label switchingMultiprotocol label switching
Multiprotocol label switchingSumita Das
 
Asymptotic analysis of parallel programs
Asymptotic analysis of parallel programsAsymptotic analysis of parallel programs
Asymptotic analysis of parallel programsSumita Das
 
Distributed systems1
Distributed systems1Distributed systems1
Distributed systems1Sumita Das
 

Plus de Sumita Das (10)

Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection method
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous search
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problems
 
Loop alignment
Loop alignmentLoop alignment
Loop alignment
 
Maps in android
Maps in androidMaps in android
Maps in android
 
Hardware and software parallelism
Hardware and software parallelismHardware and software parallelism
Hardware and software parallelism
 
Trusted systems1
Trusted systems1Trusted systems1
Trusted systems1
 
Multiprotocol label switching
Multiprotocol label switchingMultiprotocol label switching
Multiprotocol label switching
 
Asymptotic analysis of parallel programs
Asymptotic analysis of parallel programsAsymptotic analysis of parallel programs
Asymptotic analysis of parallel programs
 
Distributed systems1
Distributed systems1Distributed systems1
Distributed systems1
 

Dernier

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Activity selection problem

  • 1. AN ACTIVITY-SELECTION PROBLEM BY SUMITA DAS Created by Sumita Das
  • 2. An Activity-selection problem  Suppose we have a set of activities S={a1,a2,….,an} (Total n activities) that wish to use a common resource which can serve only one activity at a time.  Mutually exclusive access to single resource.  Each activity ai is having start time si and finish time fi, where 0<=si<=fi<∞  Goal: To find a maximum-size subset of mutually compatible activities  Compatible Activities: Activities ai and aj are compatible if si>=fj or sj>=fi i.e. Second Activity starts before first activity finishes. Created by Sumita Das
  • 3. Let set S consists of following activities which is sorted in monotonically increasing order of finish time. k 0 1 2 3 4 5 6 7 8 9 10 11 sk - 1 3 0 5 3 5 6 8 8 2 12 fk 0 4 5 6 7 8 9 10 11 12 14 16 Created by Sumita Das
  • 4. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 a11 Created by Sumita Das
  • 5. RECURSIVE-ACTIVITY-SELECTOR( s, f, k, n) 1. m= k +1 2. while m <= n and s[m] < f[k] 3. m=m +1 4. if m <= n 5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR (s, f, m, n) 6. else return Ø A Recursive Greedy Algorithm Created by Sumita Das
  • 6. s- array of start time of activities f- array of finish time of activities k- index of subproblem Sk Where Sk is the set of activities that start after activity ak finishes. n- size of original problem  Add a fictitious activity a0 with f0=0  So Subproblem S0 is entire set of activities S.  Initial call RECURSIVE-ACTIVITY-SELECTOR( s, f, 0, n) solves the entire problem Created by Sumita Das
  • 7. RECURSIVE-ACTIVITY-SELECTOR( s, f, 0, 11) 1. m= k +1 2. while m <= n and s[m] < f[k] 3. m=m +1 4. if m <= n 5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR (s, f, m, n) 6. else return Ø k=0 m=0+1=1 1<=11 and s[1]<f[0] 1<=11 1<0 false. While loop exits Return a1 U RECURSIVE- ACTIVITY- SELECTOR (s, f, 1, 11) k 0 1 2 3 4 5 6 7 8 9 10 11 sk - 1 3 0 5 3 5 6 8 8 2 12 fk 0 4 5 6 7 8 9 10 11 12 14 16 Created by Sumita Das
  • 8. RECURSIVE-ACTIVITY-SELECTOR( s, f, 1, 11) 1. m= k +1 2. while m <= n and s[m] < f[k] 3. m=m +1 4. if m <= n 5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR (s, f, m, n) 6. else return Ø k=1 m=1+1=2 2<=11 and s[2]<f[1] 3<4 true m=2+1=3 3<=11 and s[3]<f[1] 0<4 true m=3+1=4 4<=11 and s[4]<f[1] 5<4 false. While loop exits4<=11 Return a4 U RECURSIVE- ACTIVITY- SELECTOR (s, f, 4, 11) k 0 1 2 3 4 5 6 7 8 9 10 11 sk - 1 3 0 5 3 5 6 8 8 2 12 fk 0 4 5 6 7 8 9 10 11 12 14 16 Created by Sumita Das
  • 9. RECURSIVE-ACTIVITY-SELECTOR( s, f, 4, 11) 1. m= k +1 2. while m <= n and s[m] < f[k] 3. m=m +1 4. if m <= n 5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR (s, f, m, n) 6. else return Ø k=4 m=4+1=5 5<=11 and s[5]<f[4] 3<7 true m=5+1=6 6<=11 and s[6]<f[4] 5<7 true m=6+1=7 7<=11 and s[7]<f[4] 6<7 true m=7+1=8 8<=11 and s[8]<f[4] 8<7 false.While loop exits8<=11 Return a8 U RECURSIVE- ACTIVITY- SELECTOR (s, f, 8, 11) k 0 1 2 3 4 5 6 7 8 9 10 11 sk - 1 3 0 5 3 5 6 8 8 2 12 fk 0 4 5 6 7 8 9 10 11 12 14 16 Created by Sumita Das
  • 10. RECURSIVE-ACTIVITY-SELECTOR( s, f, 8, 11) 1. m= k +1 2. while m <= n and s[m] < f[k] 3. m=m +1 4. if m <= n 5. then return {am}U RECURSIVE-ACTIVITY- SELECTOR (s, f, m, n) 6. else return Ø k=8 m=8+1=9 9<=11 and s[9]<f[8] 8<11 true m=9+1=10 10<=11 and s[10]<f[8] 2<11 true m=10+1=11 11<=11 and s[11]<f[8] 12<11 falseWhile loop exits 11<=11 Return a11 U RECURSIVE- ACTIVITY- SELECTOR (s, f, 11, 11) k 0 1 2 3 4 5 6 7 8 9 10 11 sk - 1 3 0 5 3 5 6 8 8 2 12 fk 0 4 5 6 7 8 9 10 11 12 14 16 Created by Sumita Das
  • 11.  RECURSIVE-ACTIVITY- SELECTOR (s, f, 11, 11) returns Ø.  Resulting set of selected activities is {a1, a4 a8, a11} Created by Sumita Das
  • 12. References  Introduction to Algorithms 2nd ,Cormen, Leiserson, Rivest and Stein, The MIT Press, 2001.  Introduction to Design & Analysis Computer Algorithm 3rd, Sara Baase, Allen Van Gelder, Adison-Wesley, 2000. Created by Sumita Das