MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / calculate_waiting_times

Function calculate_waiting_times

scheduling/first_come_first_served.py:8–23  ·  view source on GitHub ↗

This function calculates the waiting time of some processes that have a specified duration time. Return: The waiting time for each process. >>> calculate_waiting_times([5, 10, 15]) [0, 5, 15] >>> calculate_waiting_times([1, 2, 3, 4, 5]) [0, 1, 3, 6, 10] >>> calcu

(duration_times: list[int])

Source from the content-addressed store, hash-verified

6
7
8def calculate_waiting_times(duration_times: list[int]) -> list[int]:
9 """
10 This function calculates the waiting time of some processes that have a
11 specified duration time.
12 Return: The waiting time for each process.
13 >>> calculate_waiting_times([5, 10, 15])
14 [0, 5, 15]
15 >>> calculate_waiting_times([1, 2, 3, 4, 5])
16 [0, 1, 3, 6, 10]
17 >>> calculate_waiting_times([10, 3])
18 [0, 10]
19 """
20 waiting_times = [0] * len(duration_times)
21 for i in range(1, len(duration_times)):
22 waiting_times[i] = duration_times[i - 1] + waiting_times[i - 1]
23 return waiting_times
24
25
26def calculate_turnaround_times(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected