ProgrammingVery hardTCS NQT · Accenture

Job durations (burst times) are 6, 8, 7, 3, 4 with all jobs arriving at time 0. Shortest-job-first runs them one after another in increasing order of burst time. The waiting time of a job is the sum of the bursts that run before it. What total waiting time is printed?

Job durations (burst times) are 6, 8, 7, 3, 4 with all jobs arriving at time 0. Shortest-job-first runs them one after another in increasing order of burst time. The waiting time of a job is the sum of the bursts that run before it. What total waiting time is printed?
sort bursts ascending; wait = 0; total = 0
for each burst b in sorted order
    total = total + wait
    wait = wait + b
end for
Print total
  1. A. 65
  2. B. 43
  3. C. 71
  4. D. 69

Correct answer: B. 43

Running the shortest jobs first gives waits 0, 3, 7, 13, 20 for a total of 43. The unsorted order gives 65, adding the burst times back gives the total turnaround of 71, and running the longest first gives 69.

More Pseudocode and Code Tracing questions

Exams that ask this topic