CSC264 ยท 2081 ยท 5 marks
Calculate the average waiting time and turnaround time using priority algorithm (Priority 1 being the highest) for the given scenario:
Calculate the average waiting time and turnaround time using priority algorithm (Priority 1 being the highest) for the given scenario:
$$\begin{array}{|c|c|c|c|} \hline \text{PID} & \text{Burst Time} & \text{Arrival Time} & \text{Priority} \ \hline A & 3 & 0 & 3 \ B & 2 & 2 & 3 \ C & 4 & 3 & 2 \ D & 2 & 3 & 1 \ \hline \end{array}$$
[5]
Priority Scheduling (Non-Preemptive) - Average WT and TAT
Given
| PID | Burst Time | Arrival Time | Priority |
|---|---|---|---|
| A | 3 | 0 | 3 |
| B | 2 | 2 | 3 |
| C | 4 | 3 | 2 |
| D | 2 | 3 | 1 |
Priority 1 = highest. Assume non-preemptive priority scheduling.
Solution
Execution Order
- t = 0: Only A available โ A runs 0 to 3.
- t = 3: Ready = B (P3), C (P2), D (P1). Highest priority = D โ D runs 3 to 5.
- t = 5: Ready = B (P3), C (P2). Higher priority = C โ C runs 5 to 9.
- t = 9: Only B remains โ B runs 9 to 11.
Gantt Chart
| A | D | C | B |
0 3 5 9 11
Completion, Turnaround, Waiting Times
TAT = CT โ AT, WT = TAT โ BT
| PID | AT | BT | CT | TAT = CTโAT | WT = TATโBT |
|---|---|---|---|---|---|
| A | 0 | 3 | 3 | 3 | 0 |
| B | 2 | 2 | 11 | 9 | 7 |
| C | 3 | 4 | 9 | 6 | 2 |
| D | 3 | 2 | 5 | 2 | 0 |
Averages
$$\text{Avg TAT} = \frac{3 + 9 + 6 + 2}{4} = \frac{20}{4} = 5 \text{ ms}$$
$$\text{Avg WT} = \frac{0 + 7 + 2 + 0}{4} = \frac{9}{4} = 2.25 \text{ ms}$$
Final Result
| Metric | Value |
|---|---|
| Average Turnaround Time | 5 ms |
| Average Waiting Time | 2.25 ms |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.