We are given 9 tasks T1, T2.... T9. The execution of each task requires one…

2005

We are given 9 tasks T1, T2.... T9. The execution of each task requires one unit of time. We can execute one task at a time. Each task Ti has a profit Pi and a deadline di Profit Pi is earned if the task is completed before the end of the dith unit of time.

Task     T1  T2	 T3  T4  T5  T6	 T7 T8  T9
Profit   15  20	 30  18  18  10	 23 16  25
Deadline 7   2 	 5   3 	 4   5 	 2  7   3 

Are all tasks completed in the schedule that gives maximum profit?

  1. A.

    All tasks are completed

  2. B.

    T1 and T6 are left out

  3. C.

    T1 and T8 are left out

  4. D.

    T4 and T6 are left out

Attempted by 103 students.

Show answer & explanation

Correct answer: D

Key insight: use a greedy algorithm: sort tasks by descending profit and place each task in the latest available slot on or before its deadline.

  • Step 1: Sort tasks by profit (profit, task, deadline): 30 T3 (d5), 25 T9 (d3), 23 T7 (d2), 20 T2 (d2), 18 T4 (d3), 18 T5 (d4), 16 T8 (d7), 15 T1 (d7), 10 T6 (d5).

  • Step 2: Place each task into the latest free slot ≤ its deadline:

    • Place T3 (30) in slot 5.

    • Place T9 (25) in slot 3.

    • Place T7 (23) in slot 2.

    • Place T2 (20) in the latest free slot ≤2, which is slot 1.

    • T4 (18) cannot be placed (slots 1–3 are full), so skip it.

    • Place T5 (18) in slot 4.

    • Place T8 (16) in slot 7; place T1 (15) in slot 6.

    • T6 (10) cannot be placed (all slots ≤5 are full), so skip it.

  • Final scheduled slots (1 to 7): slot1 = T2 (20), slot2 = T7 (23), slot3 = T9 (25), slot4 = T5 (18), slot5 = T3 (30), slot6 = T1 (15), slot7 = T8 (16).

  • Tasks left out: T4 and T6.

  • Total profit from scheduled tasks = 20 + 23 + 25 + 18 + 30 + 15 + 16 = 147.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir