retagged by
738 views
1 1 vote
Consider a process scenario with n processes (n>1) with process ids P0, P1, ….,Pn-1; with all processes arrive at time 0. The arrival times of all processes are stored in an array AT[] of size n with arrival time of process P0 at index 0, arrival time of process P1 at index 1 and so on. The burst times of processes are stored in an array BT[] of size n with burst time of process P0 at index 0, burst time of process P1 at index 1 and so on. Sum of the burst times of all processes is equal to 4n. The run time taken to execute all processes in single CPU (including the scheduler time to decide which process to run next), using FCFS and non-preemptive Shortest Job First scheduling can be given respectively as:

1.O(n) and O(n)

2.O(n) and O(n logn)

3.O(n) and O(n2)

4.O(n2) and O(n2)

answer is 3 why not 2..

1 Answer

0 0 votes

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.

edited by
Position:
Show:

Related questions

1 1 vote
1 1 answer
117
117 views
GO Classes asked Aug 26
117 views
A system uses two feedback queues:$\text{Q1}$: Round Robin with time quantum $10$ ms $\text{Q2}$: Shortest Job First $\text{Q1}$ has higher priority than $\text{Q2}$ New ...
2 2 votes
2 2 answers
281
281 views
GO Classes asked Aug 3
281 views
Four processes arrive at time $0$ in the following order:$P_1,\ P_2,\ P_3,\ P_4$Their CPU burst times are:$P_1=8$$P_2=4$$P_3=2$$P_4=1$Calculate the difference between the...
4 4 votes
1 1 answer
230
230 views
GO Classes asked Jul 18
230 views
Which of the following statements are correct?The CPU dispatcher determines the policy for which process should be run and when. With cooperative multitasking, it is poss...
0 0 votes
1 1 answer
375
375 views
NIL DAS asked Oct 9, 2025
375 views
[MSQ]1. Producer Consumer problem has .(a) Competition (b) Co-operation(c) Inconsistency (d) Data loss