Take an example p0,p1,p2,p3,p4,p5,pn-1
For FCFS Algo you will execute the process one by one as all the process arriving at same time you only need to traverse till n-1.
O(n)
for(i=0;i<n;i++){
execute(pn);
}
For Non-Preemptive SJF You need to find the Minimum Burst Time every time in all the N processes. p0,p1,p2,p3 are given their total burst time can be 4*n = 16. Execute once using the first loop and find 1st minimum using the second loop after finding the minimum execute that process with the minimum value then go to the first loop and do it again and again till n-1. Read Code for better understanding.
O(n2)
for(i=0;i<n;i++){
int index;//used to store the minimum Burst time Process index
int m=INT_MAX;//variable for minimum burst value
for(j=0;j<n;j++){
if(b[j]<m){// if less than m go inside the loop
m=b[j]; //update the minimum burst value
index=j;//store the index which have minimum burst value
}
}
//Now You have the index of Process which have min BT
//Execute the Process with given index
execute(p[index]);
//Intialize p[index] as INT_MAX so it won’t execute again.
p[index]=INT_MAX;
}
You can dry-run the code for better understanding.