63.4k views
3 votes
A computing company is running a set of processes every day. Each process has its own start time and finish time, during which it runs continuously. The company has developed a process_check module, that runs briefly (consider this to take just 1 point in time) and records important pieces of information about the processes running at that time. The company would like to run the process_check module as few times as possible each day, while making sure that the module is called at least once during the execution of each process.

Required:

Give an efficient algorithm that based on the start and finish time of each process will find the smallest set of possible moments of time at which to run the process_check module (making sure that the module is invoked at least once for each process).

User TheGeeky
by
4.5k points

1 Answer

2 votes

Answer:

Above all else, let us show that this issue has the greedy choice property.

This implies that worldwide ideal arrangement can be gotten by choosing local ideal arrangements. Presently notice the following:

The global optimal solution of the issue requests us to track down the minimum number of times process_check module should be run.

It is likewise referenced that during each running interaction, process_check module should be called atleast once. Along these lines, the minimum possible number of process_check calls happens when process_check is made close to the quantity of the processes that are run.

Along these lines, we see that the global optimal solution is shaped by choosing optimal answer for the nearby advances.

Along these lines, the issue shows greedy choice property. Thus, we can utilize a greedy algorithm for this issue.

The greedy step in this calculation is to postpone the process_check as far as might be feasible. Thus, it should be run towards the finish of each interaction. So the following algorithm can be utilized:

Sort the cycles by utilizing the completion times.

Towards the finish of the 1st process in the arranged list, run the process_check module. Right now any process that is now running is removed the arranged rundown. The main interaction is additionally removed from the sorted list.

Now repeat stage 2, till all processes are finished.

In the above mentioned algorithm, the costliest advance is the step of sorting. By utilizing the optimal sorting algorithm, for example, merge sort, we can achieve it in O(n log n) asymptotic time.

Along these lines, this greedy algorithm additionally takes O(n log n) asymptotic time complexity.

User Avnish
by
3.9k points