How to calculate average waiting time for round robin cpu scheduling? I have tried to calculate average waiting time for the below details there are two answers I'm getting using two methods I'm not understanding which one is correct?

The time quantum is 2
This is the first method:

Process Id         Arrival Time        Burst Time 
P0                      0                   5
P1                      1                   3
P2                      2                   1
P3                      3                   2
P4                      4                   3


This is the first gantt chart:

P0      P1      P2      P0      P2      P4      P1          P0          P4
0-2     2-4     4-5     5-7     7-9     9-11    11-12       12-13       13-14

Process Id         Waiting Time 
P0                     8
P1                     8
P2                     2
P3                     4
P4                     7



  Average waiting time1: 29/5=5.8


And this is the second method:

This is the second gantt chart:

P0      P1      P2      P3      P4      P0      P1          P4          P0
0-2     2-4     4-5     5-7     7-9     9-11    11-12       12-13       13-14


Process Id         Waiting Time 
P0                     9
P1                     8
P2                     2
P3                     2
P4                     6



  Average waiting time2: 27/5=5.4
The average waiting time would depend on the order in which the processes are scheduled. Your round-robin scheduler does not mention of an optimization scheme to minimize the waiting time. Both schedules listed out are correct and produce the respective waiting times.