ProgrammingHardTCS NQT · Accenture
Seven tasks with durations 7, 5, 4, 3, 2, 2, 1 are assigned to two identical machines. Tasks are taken in decreasing duration order, and each goes to the machine that currently has the smaller total load (ties go to machine 1). The makespan is the larger final load. What is printed as the makespan?
Seven tasks with durations 7, 5, 4, 3, 2, 2, 1 are assigned to two identical machines. Tasks are taken in decreasing duration order, and each goes to the machine that currently has the smaller total load (ties go to machine 1). The makespan is the larger final load. What is printed as the makespan?
sort durations descending; load1 = load2 = 0
for each duration d
if load1 <= load2 then load1 = load1 + d else load2 = load2 + d
end for
Print max(load1, load2)- A. 14
- B. 24
- C. 12
- D. 13
Correct answer: C. 12
Taking 7 and 5 first, each later job goes to the lighter machine, and the loads finish at 12 and 12, so the makespan is 12. Taking the smallest jobs first gives 14, piling every job onto the heavier machine gives 24, and the rounded half of the total gives 13.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Array a = [2, 5, 3, 5]. For every pair of positions i < j, count the pairs where a[i] is at most a[j] (a[i] <= a[j]). What is the printed…
- Array a = [4, -2, 5, -1, 3]. Exactly k = 2 negations are applied: each one chooses the currently smallest element and replaces it by its…
- Tasks (duration, deadline): (3,5), (2,4), (4,9), (1,3). Earliest deadline first is applied: tasks are sorted by deadline and run back to…
- Two positive integers are a = 252 and b = 105. The procedure below finds their gcd by repeated subtraction. How many times does the loop…
- Let N = 360. The procedure below counts the divisors of N by testing every i from 1 to N. What is printed? count = 0 for i = 1 to N if N…
- A number's digit sum is computed by the procedure below for N = 98765. What is printed? s = 0; m = N while m > 0 s = s + (m mod 10) m = m…