ProgrammingVery hardCAT · MBA placement

Five jobs each take one time unit. Job (name, deadline, profit): a (2,100), b (1,19), c (2,27), d (1,25), e (3,15). A job earns its profit only if it finishes by its deadline, and slots are 1, 2, 3. The procedure below runs on these jobs. What is printed?

Five jobs each take one time unit. Job (name, deadline, profit): a (2,100), b (1,19), c (2,27), d (1,25), e (3,15). A job earns its profit only if it finishes by its deadline, and slots are 1, 2, 3. The procedure below runs on these jobs. What is printed?
sort jobs by profit, highest first
for each job j in that order
    for t = deadline of j down to 1
        if slot t is free then
            occupy slot t; total = total + profit of j; stop with this job
        end if
    end for
end for
Print total
  1. A. 186
  2. B. 142
  3. C. 61
  4. D. 152

Correct answer: B. 142

Each slot holds one job, and a job takes the latest free slot before its deadline so early slots stay open for tight jobs. Ignoring deadlines gives 186, sorting by profit ascending gives 61, and taking the top three profits without checking slots gives 152, which is infeasible.

More Pseudocode and Code Tracing questions

Exams that ask this topic