Algorithm question 3) Round Robin CRR): Jobs are processed using a fixed time-sl
ID: 3833652 • Letter: A
Question
Algorithm question 3) Round Robin CRR): Jobs are processed using a fixed time-slice. The jobs are initially kept in a queue based on the order of arrival. The job at the front of the queue is removed and served similar to the FIFO algorithm. However, unlike the FIFO algorithm, each job is served up to the pre-defined slice of time. If job can be completed within the allotted time it is fully served and removed from the queue. the job cannot be completed in the allotted time, it is served for the allotted time and then added to the end of the queue to be served later for the remaining time. This process is continued until the queue is empty. The total turnaround time is the total time a job spends in the system: Turnaround time processing time waiting time (time s in queue). For example, it the work load is 15 units, but it spends 50 units of time in queue, waiting to be processed, then the turnaround time is equal to 65 units. A) Write a program to test the effectiveness of these algorithms. Create 100 jobs, each with a random processing time of 0 to 100 time units. Then process the jobs according to the above scheduling methods. You can use an ArrayList for the FIFO and RR scheduling schemes. Implement the SJF using a binary heap (priority heap). Use a time slice of 20 units. Compare the average turnaround time for the different strategies. B) Experiment with different time slic for the RR strategy and compare the results. Use time slices in increments of 5 units and see if are any differences in the average turnaround time.Explanation / Answer
//Java Program for Round Robin Algorithm
import java.io.*;
import java.util.*;
public class RR
{
public static void main(String args[])throws IOException
{
Random rand=new Random();
DataInputStream in=new DataInputStream(System.in);
int i,j,k,q,sum=0;
int n=100;
int bt[]=new int[n];
int wt[]=new int[n];
int tat[]=new int[n];
int a[]=new int[n];
for(i=0;i<n;i++)
{
//Generating random numbers between 1 to 100
bt[i]=rand.nextInt(100)+1;
}
q=20;
for(i=0;i<n;i++)
a[i]=bt[i];
for(i=0;i<n;i++)
wt[i]=0;
do
{
for(i=0;i<n;i++)
{
//Checking Bt is greather than q
if(bt[i]>q)
{
bt[i]-=q;
for(j=0;j<n;j++)
{
if((j!=i)&&(bt[j]!=0))
wt[j]+=q;
}
}
else
{
for(j=0;j<n;j++)
{
if((j!=i)&&(bt[j]!=0))
wt[j]+=bt[i];
}
bt[i]=0;
}
}
sum=0;
//Checking all proess are finished or not
for(k=0;k<n;k++)
sum=sum+bt[k];
}
while(sum!=0);
for(i=0;i<n;i++)
tat[i]=wt[i]+a[i];
//BT=Burst Time WT=Waiting time //TAT=Turnaround Time
System.out.println("process BT WT TAT");
for(i=0;i<n;i++)
{
System.out.println("process"+(i+1)+" "+a[i]+" "+wt[i]+" "+tat[i]);
}
float avg_wt=0;
float avg_tat=0;
for(j=0;j<n;j++)
{
avg_wt+=wt[j];
}
for(j=0;j<n;j++)
{
avg_tat+=tat[j];
}
System.out.println("average waiting time "+(avg_wt/n)+" Average turn around time"+(avg_tat/n));
}
}
/*
process BT WT TAT
process1 1 0 1
process2 4 1 5
process3 62 3685 3747
process4 42 2902 2944
process5 71 3687 3758
process6 32 1759 1791
process7 2 85 87
process8 18 87 105
process9 99 4130 4229
process10 57 2944 3001
process11 47 2961 3008
process12 99 4149 4248
process13 13 185 198
process14 86 4168 4254
process15 32 1871 1903
process16 39 1883 1922
process17 69 3758 3827
process18 11 278 289
process19 18 289 307
process20 98 4174 4272
process21 14 327 341
process22 63 3787 3850
process23 67 3790 3857
process24 23 1982 2005
process25 6 401 407
process26 55 3088 3143
process27 10 427 437
process28 1 437 438
process29 35 2005 2040
process30 30 2020 2050
process31 68 3797 3865
process32 63 3805 3868
process33 21 2070 2091
process34 23 2071 2094
process35 45 3143 3188
process36 80 3808 3888
process37 28 2114 2142
process38 87 4192 4279
process39 97 4199 4296
process40 11 658 669
process41 25 2162 2187
process42 16 689 705
process43 33 2167 2200
process44 61 3868 3929
process45 19 745 764
process46 100 4216 4316
process47 25 2220 2245
process48 9 804 813
process49 91 4236 4327
process50 37 2245 2282
process51 13 853 866
process52 14 866 880
process53 55 3268 3323
process54 46 3283 3329
process55 5 920 925
process56 6 925 931
process57 51 3289 3340
process58 93 4247 4340
process59 10 971 981
process60 3 981 984
process61 46 3320 3366
process62 32 2362 2394
process63 11 1024 1035
process64 26 2374 2400
process65 94 4260 4354
process66 85 4274 4359
process67 24 2420 2444
process68 27 2424 2451
process69 13 1135 1148
process70 15 1148 1163
process71 95 4279 4374
process72 39 2451 2490
process73 32 2470 2502
process74 95 4294 4389
process75 33 2502 2535
process76 35 2515 2550
process77 12 1283 1295
process78 60 3406 3466
process79 63 4009 4072
process80 27 2570 2597
process81 55 3446 3501
process82 36 2597 2633
process83 70 4012 4082
process84 87 4309 4396
process85 85 4316 4401
process86 99 4321 4420
process87 85 4340 4425
process88 1 1495 1496
process89 57 3561 3618
process90 79 4102 4181
process91 83 4345 4428
process92 18 1556 1574
process93 60 3618 3678
process94 29 2793 2822
process95 69 4141 4210
process96 51 3658 3709
process97 52 3669 3721
process98 46 3681 3727
process99 5 1694 1699
process100 58 3687 3745
average waiting time 2579.33
Average turn around time2623.61
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.