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- A. 186
- B. 142
- C. 61
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Train (arrival, departure) times in HHMM form: arrivals 900, 940, 950, 1100, 1500, 1800 and departures 910, 1200, 1120, 1130, 1900, 2000…
- Coin denominations are 1, 4 and 5. The greedy method for amount 8 considers denominations from largest to smallest and takes each coin…
- Fractional knapsack with capacity 50. Items as (value, weight): (60,10), (100,20), (120,30). Items are sorted by value per unit weight…
- Gas stations on a circle: gas = [1,2,3,4,5], cost = [3,4,5,1,2]. Station i gives gas[i] and then costs cost[i] to leave for station i+1…
- Ropes are to be merged into one. Merging two ropes of lengths a and b costs a + b and yields one rope of length a + b. Ropes have lengths…
- Stock prices by day: 3, 8, 2, 9, 1, 6. One share may be bought once and sold once later (later day only). The procedure below runs. What…