0
votes

i am trying to understand how shortest job first algorithm works, am i doing this in the right way please help

Proc     Burst1    Burst2
+------+---------+--------+
|  A   |   10    |   5    |
|  B   |   3     |   9    |
|  C   |   8     |   11   |
+------+---------+--------+

B1->3->C1->11->B2->20->A1->30->A2->35->C2->46
1
Unless you have some Java code to show, I'm removing that tag.Joe Frambach
Looks right, after I managed to guess what you actually meant with the table and the steps underneath. What exactly is your question? Is your question perhaps how to implement it (in Java)?Ulrich Eckhardt
i just want to know if the answer is correct @doomsterKarish Karish

1 Answers

1
votes

"Shortest job first" is not really an algorithm, but a strategy: among the jobs ready to execute always choose the job with the shortest execution time. Your sequence looks ok. In the beginning the following jobs are ready for execution (with execution time in parenthesis):

A1(10), B1(3), C1(8)

So B1 is chosen, after which also job B2 is ready to execute, so here is the updated list of ready jobs:

A1(10), B2(9), C1(8)

Now C1 is chosen, and so on.

There are variants of the strategy "shortest job first", where the total time over all bursts, i.e. A1 + A2, B1 + B2, ..., is taken into account. Then the chosen sequence would be:

B1, B2, A1, A2, C1, C2