Question: When multiple tasks are executed on a single - threaded CPU, the tasks are scheduled based on the principle of pre - emption. When a

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 in 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 (function_id):("start"|"end"): (timestamp), indicating that the function with ID = function_id, either starts or ends at a time identified by the timestamp value.
Note: While calculating the execution time of a function call, both the starting and ending times of the function call have to be included. The log of the form (function_id):(start): (timestamp) means that the running function is preempted at the beginning of timestamp second. The log of the form (function_id):(end): (timestamp) means that the function function_id is preempted after completing its execution at timestamp second i.e after timestamp second.
Example
Suppose n=3, logs =["0:start:0","2:start:4","2:end:5","1:start:7","1:end:10","0:end:11"]

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!