USE PYTHON LANGUAGE. READ INPUT FROM FILE (NAME THE FILE "input.txt') The problem needs to be solved using Greedy Algorithm Strategy. Problem: . Each activity has a time interval- i.e. a start and a finish time. The activities can be distributed between M people. Implement a greedy algorithm to find the total number of activities that can be completed by M people. The following conditions must be met when writing the code: One person cannot do activities with overlapping time intervals, so each person can do only one activity at a given time interval. Each activity can be completed by only one person. The input will contain N and M, and then N lines with the start time and finish time in the format given below: N M S₁ F₁ S₂ F₂ ……. Sn Fn You have to read input from a file. The output will contain the total number of activities that can be completed. Sample input and output are given below. Name your input file “input.txt”. Make sure to try out different input examples to ensure that your code is working for different cases. Include the input file in your zipped submission folder. Input 1: 5 2 1 5 3 6 2 5 8 10 6 9 Input 2: 3 2 3 6 2 4 2 3 Output 1: 4 Output 2: 3 The image pseudocode has been given. You have to modify the pseudocode to solve the problem.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

USE PYTHON LANGUAGE.

READ INPUT FROM FILE (NAME THE FILE "input.txt')

The problem needs to be solved using Greedy Algorithm Strategy.

 

Problem:

 

 . Each activity has a time interval- i.e. a start and a finish time. The activities can be distributed between M people. Implement a greedy algorithm to find the total number of activities that can be completed by M people. The following conditions must be met when writing the code:

  1. One person cannot do activities with overlapping time intervals, so each person can do only one activity at a given time interval. 
  2. Each activity can be completed by only one person.

The input will contain N and M, and then N lines with the start time and finish time in the format given below:

 

N M

S₁ F₁

S₂ F₂

…….

Sn Fn

 

You have to read input from a file. The output will contain the total number of activities that can be completed. Sample input and output are given below.  Name your input file “input.txt”. Make sure to try out different input examples to ensure that your code is working for different cases. Include the input file in your zipped submission folder.



Input 1:

5 2

1 5

3 6

2 5

8 10

6 9

Input 2:

3 2

3 6

2 4

2 3

Output 1:

4

Output 2:

3

 

 The image pseudocode has been given. You have to modify the pseudocode to solve the problem. 

 

A greedy algorithm for scheduling all intervals
SCHEDULE-INTERVALS(/)
DI = {I;}, l; = (si, fi)
1 R= Sorted requests in order of starting times, breaking ties
arbitrarily, such that s; < s; when i<j.
m – OD the optimal number of resources needed to schedule R
3 while R+ Ø
2
do req = extract the next element in R
if there is a resource j with no interval conflicting with req
then schedule interval req on resource j
4
6.
7
else
8.
m – m+1
D allocate a new resource
9.
schedule interval req on resource m
Transcribed Image Text:A greedy algorithm for scheduling all intervals SCHEDULE-INTERVALS(/) DI = {I;}, l; = (si, fi) 1 R= Sorted requests in order of starting times, breaking ties arbitrarily, such that s; < s; when i<j. m – OD the optimal number of resources needed to schedule R 3 while R+ Ø 2 do req = extract the next element in R if there is a resource j with no interval conflicting with req then schedule interval req on resource j 4 6. 7 else 8. m – m+1 D allocate a new resource 9. schedule interval req on resource m
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY