# Using SJN, how do I calculate the start and finish time for …

Using SJN, how do I calculate the start and finish time for each of the seven jobs below: Job   Arrival Time    CPU Cycle A         0              2 B         1              11 C         2              4 D         4              1 E         5              9 F         7              4 G         8              2

To calculate the start and finish time for each job using the Shortest Job Next (SJN) scheduling algorithm, we need to consider the arrival time and CPU cycles of each job. In SJN, the job with the smallest CPU cycle is executed first.

First, let’s sort the jobs based on their arrival time in ascending order:

Job Arrival Time CPU Cycle
A 0 2
B 1 11
C 2 4
D 4 1
E 5 9
F 7 4
G 8 2

Now, let’s calculate the start and finish time for each job:

Job A (Arrival Time: 0, CPU Cycle: 2):
Since no other job arrives before Job A, it can start executing immediately. The start time for Job A is 0, and it finishes at time 2.

Job B (Arrival Time: 1, CPU Cycle: 11):
Job B arrives at time 1, and it has the highest CPU cycle among all the jobs. However, it cannot start executing immediately because Job A is already running. Job B needs to wait until Job A completes its execution. Therefore, Job B starts at time 2, which is when Job A finishes, and finishes at time 13.

Job C (Arrival Time: 2, CPU Cycle: 4):
Job C arrives at time 2, and it has a lower CPU cycle than Job B. However, Job C still needs to wait until Job B completes its execution because it arrives after Job B. Job C starts at time 13, which is when Job B finishes, and finishes at time 17.

Job D (Arrival Time: 4, CPU Cycle: 1):
Job D arrives at time 4. Since Job C is still running, Job D needs to wait until Job C completes its execution. Hence, Job D starts at time 17, which is when Job C finishes, and finishes at time 18.

Job E (Arrival Time: 5, CPU Cycle: 9):
Job E arrives at time 5. It needs to wait for Job D to complete because Job D has a lower arrival time (Job D arrives before Job E) and is still executing. Job E starts at time 18, which is when Job D finishes, and finishes at time 27.

Job F (Arrival Time: 7, CPU Cycle: 4):
Job F arrives at time 7. It needs to wait for Job E to complete because Job E has a lower arrival time (Job E arrives before Job F) and is still executing. Job F starts at time 27, which is when Job E finishes, and finishes at time 31.

Job G (Arrival Time: 8, CPU Cycle: 2):
Job G arrives at time 8. It needs to wait for Job F to complete because Job F has a lower arrival time (Job F arrives before Job G) and is still executing. Job G starts at time 31, which is when Job F finishes, and finishes at time 33.

So, the start and finish times for each job using the SJN scheduling algorithm are as follows:

Job Start Time Finish Time
A 0 2
B 2 13
C 13 17
D 17 18
E 18 27
F 27 31
G 31 33

Note that SJN scheduling algorithm minimizes the average waiting time and run-time for a set of jobs, but it may lead to a situation where longer jobs have to wait for shorter jobs to complete, resulting in a longer overall execution time.

The post Using SJN, how do I calculate the start and finish time for … appeared first on My Perfect Tutors.