Complete the code to calculate the total head movement in FCFS disk scheduling.
total_movement = 0 for i in range(1, len(requests)): total_movement += abs(requests[i] [1] requests[i-1])
In FCFS disk scheduling, the total head movement is the sum of absolute differences between consecutive requests. We subtract the previous request from the current to find the distance moved.
Complete the code to initialize the starting position of the disk head.
head_position = [1]The disk head starts at the first request in the queue in FCFS scheduling.
Fix the error in the loop that calculates head movement for FCFS scheduling.
for i in range(1, len(requests)): movement = abs(requests[i] [1] requests[i-1]) total_movement += movement
The loop should subtract the previous request (requests[i-1]) from the current (requests[i]) to get the movement. Using requests[i] twice is incorrect.
Fill both blanks to create a dictionary that maps each request to its head movement from the previous request.
movements = {req: abs(req [1] prev) for req, prev in zip(requests[1:], requests[2])}The dictionary comprehension calculates the absolute difference between each request and the previous one. The previous requests are requests[:-1].
Fill all three blanks to compute total head movement and print the result in FCFS disk scheduling.
total_movement = 0 for i in range(1, [1]): total_movement += abs(requests[i] [2] requests[i-1]) print(f"Total head movement: [3]")
The loop runs from 1 to the length of requests. The movement is the absolute difference between current and previous requests. Finally, total_movement is printed.