Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: You need to simulate the execution of a set of tasks that are given to you. Assume that there are an infinite number of

Question:

You need to simulate the execution of a set of tasks that are given to you. Assume that there are an infinite number of processors available, so that each task starts as soon as it becomes ready. This means that you need to keep track of which tasks are active at any given point in time, and remove them from the active list as they finish.

Assume that the input consists of a set of tasks given in increasing order of start time, and each task has a certain duration associated. First line of the file is number of tasks. For example,

---

3

2 5

4 23

7 4

---

This means that there are 3 tasks. The first one starts at time 2, and ends at 7 (2+5). Second starts at 4, ends at 27. Third starts at 7, ends at 11. We assume each task starts as soon as it is ready, and does not need to wait for a processor or anything else to free up.

This means we can keep track of number of active tasks as follows:

Time #tasks

0 - 2 0

2 - 4 1

4 - 7 2

7 - 11 2

11 - 27 1

* End of simulation timeExpected output is 3 numbers:The simulation ends at T=27.

* Max number of active tasks at any given time

* Average number of active tasks over the entire duration, printed to 4 decimal places (use printf("%.4f"))

So expected output for the above inputs is:

---

27

2

1.1852

---

Average active tasks over entire duration is computed here as :

[ 0x(2-0) + 1x(4-2) + 2x(11-4) + 1x(27-11) ] / 27

Assume number of tasks can be up to 1,000,000. Minimum duration of a task is 1 (all durations and start times integers) and max duration of a task is 1000. Earliest possible start time is 0.

My attempt:

I have used C++ for this. I have been able to get the first output. How do I get the other two?

image text in transcribed

#include #include "stdio.h" "stdlib.h" typedef struct tong int start; int dur ) task; int main) long int num tasks, endtime; tong int maxtime0 scanf("%ld" ,&num-tasks); task *t new task(num-tasks); scanf("Ald %d",&t [1].start,&t [i].dur); endtime til start +tli,dur: if (endtime maxtime) maxtime-endtime printf("idn" ,maxtime)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions