Question: [ 5 : 0 9 PM , 1 2 / 2 7 / 2 0 2 3 ] Janarthanan Uniq: When multiple tasks are executed

[5:09 PM,12/27/2023] Janarthanan Uniq: When multiple tasks are executed on a single-threaded CPU, the tasks are scheduled based on the principle of pre-emption. When a higher-priority task arrives in the execution queue, then the lower-priority task is pre-empted, i.e. its execution is paused until the higher-priority task is complete.
There are n functions to be executed on a single-threaded CPU, with each function having a unique ID between 0 and n -1 Given an integer n, representing the number of functions to be executed, and an execution log as an array of strings, logs, of size m, determine the exclusive times of each of the functions. Exclusive time is the sum of execution times for all calls to a function. Any string representing an execution log is of the form \{functionid\} :\^ prime ...
[5:09 PM,12/27/2023] Janarthanan Uniq: Example
Suppose n =3 logs=[^ prime prime 0/ s * tart :0^ prime prime ,"2:start:4","2:end:5","1:start:7","1:end:10","0/ e * nd /11"]
Timestamp
Function Running
Remarks
0
0
Function 0 starts
1
0
2
0
3
0
4
2
Function 2 starts and Function 0 is preempted
5
2
Function 2 ends
6
0
Function O resumes
7
1
Function 1 starts and Function 0 is preempted
8
1
1
9
10
1
Function 1 ends
11
0
Function O ends
[5:09 PM,12/27/2023] Janarthanan Uniq: Thus the total number of seconds allocated to functions 0,1, and 2 are 6,4, and 2 respectively. Hence the answer is [6,4,2]
Function Description
Complete the function getTotal ExecutionTime in the editor below.
getTotalExecutionTime has the following parameters:
int n: the number of functions to be executed
string logs[m]: the execution logs of the different calls to the functions
Returns
integrate [n] dn the execution time of all functions with IDs from 0 n -1.
Constraints
.1<= n <=100
1<= m <=500
.0<= function .id logs = IntStream.range(0, logsCount).mapToobj ( i -> f
try {
return bufferedReader.readLine();
} catch (IOException ex){
throw new RuntimeException(ex);
}
})
.collect(toList());
result Result getTotal ExecutionTime(n. logs):
[5:09 PM,12/27/2023] Janarthanan Uniq: bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(joining("
"))
+"
"
);
bufferedReader.close(); bufferedWriter.close();
}
}
[5:09 PM,12/27/2023] Janarthanan Uniq: class Result {
public static List getTotal ExecutionTime(int n, List
logs){
// Write your code here
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!