THINK FIRST·CODE LATER

← All labs

HRRN with the decision trace

Problem

Implement Highest Response Ratio Next (non-preemptive) and show the reasoning at every decision.

Input: lines name arrival burst until the end of input.

Whenever the CPU is free at time t, compute for every arrived, unfinished process the ratio R = (W + S) / S, where W = t − arrival and S = burst. Print

t=9: ratios C=2.25, D=1.60, E=1.50 -> run C

(ratios with two decimals, processes in input order; ties go to the earlier process in input order), then run the chosen process to completion. If nothing has arrived, the CPU is idle until the next arrival (no line is printed for the idle period, but it appears in the Gantt chart as idle s-e).

At the end print Gantt: | A 0-3 | ... |, Average turnaround: x.xx and Average waiting: x.xx.

Input:

A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Output:

t=0: ratios A=1.00 -> run A
t=3: ratios B=1.17 -> run B
t=9: ratios C=2.25, D=1.60, E=1.50 -> run C
t=13: ratios D=2.40, E=3.50 -> run E
t=15: ratios D=2.80 -> run D
Gantt: | A 0-3 | B 3-9 | C 9-13 | E 13-15 | D 15-20 |
Average turnaround: 8.00
Average waiting: 4.00

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.