ProgrammingHardTCS NQT · Accenture
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 back from time 0. Lateness of a task is finish time minus deadline. What is printed as the maximum lateness?
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 back from time 0. Lateness of a task is finish time minus deadline. What is printed as the maximum lateness?
sort tasks by deadline ascending
time = 0; best = negative infinity
for each (d, dl) in sorted order
time = time + d
best = max(best, time - dl)
end for
Print best- A. 7
- B. 2
- C. 20
- D. 1
Correct answer: D. 1
Sorted by deadline, the finish times are 1, 3, 6 and 10 against deadlines 3, 4, 5 and 9, so the largest lateness is 1 (the third task). Input order gives 7, counting late tasks gives 2, and summing the finish times gives 20.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- 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…
- The procedure below uses the sieve of Eratosthenes on the range 2 to 50, marking composites starting from ii. The inner marking statement…
- Compute 3^13 mod 7 with the binary method below (a = 3, e = 13, m = 7). What is printed? result = 1; base = a mod m; e = 13 while e > 0 if…
- Let phi(n) be the number of integers i with 1 <= i <= n that share no common factor with n except 1. The procedure below computes phi(36)…