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- A. 65
- B. 43
- C. 71
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- A row of positions 1 to 20 is scanned in order. A position i is picked if no position has been picked yet, or if i minus the last picked…
- Array a = [2,3,1,1,4,2,1,3,1,1] (0-based). From index i you may jump forward at most a[i] positions. Starting at index 0, the greedy below…
- Tasks with the same letter must be separated by at least n = 2 idle or other slots. The task string is AAABBC. The greedy formula below…
- Items of sizes 5, 7, 5, 2, 4, 2, 5, 1, 6 are packed in this order into bins of capacity 10 using the first-fit rule: put each item into…
- Coins are 1, 5, 10, 21 and 25. To pay 63, the greedy method below always takes the largest coin that fits, using the list in descending…
- Intervals (start, end): (1,10), (2,3), (4,5), (6,7), (8,9). The greedy below selects the largest set of pairwise disjoint intervals…