2078 6

CSC325 · 2078 · 5 marks

Explain the algorithm and its complexity for solving job sequencing with deadline problem using greedy strategy.

Explain the algorithm and its complexity for solving job sequencing with deadline problem using greedy strategy. [5]

Design and Analysis of AlgorithmsChapter 4: Greedy AlgorithmsGreedy Algorithms

Quick answer

Given n jobs, each with a deadline and a profit (earned only if the job is completed by its deadline), find a feasible sequence of jobs that maximizes total profit. Each job takes unit time to complete and only one machine (processor) is available.

Job Sequencing with Deadlines - Greedy Strategy

Problem Statement


Greedy Strategy

The greedy approach selects jobs in decreasing order of profit (most profitable job first) and schedules each job in the latest available time slot before its deadline.


Algorithm

JobSequencingWithDeadline(D, J, n, k)

1. Sort all jobs in decreasing order of profit P.
2. D(0) = J(0) = 0
3. k = 1
4. J(1) = 1        // Select the first (highest profit) job
5. for i = 2 to n do:
      r = k
      while D(J(r)) > D(i) and D(J(r)) ≠ r do:
          r = r - 1
      if D(J(r)) ≤ D(i) and D(i) > r then:
          for l = k downto r+1 do:
              J(l+1) = J(l)
          J(r+1) = i
          k = k + 1
6. Output J(1), J(2), ..., J(k)  // Feasible job sequence with max profit

Step-by-Step Example

JobDeadlineProfit
J12100
J2119
J3227
J4125
J5315

After sorting by profit (descending): J1(100), J3(27), J4(25), J2(19), J5(15)

  • Select J1 → place at slot 2 → Schedule: [_, J1]
  • Select J3 → deadline 2, slot 1 is free → Schedule: [J3, J1]
  • Select J4 → deadline 1, slot 1 is taken → skip
  • Select J2 → deadline 1, slot 1 is taken → skip
  • Select J5 → deadline 3, slot 3 is free → Schedule: [J3, J1, J5]

Result: J3, J1, J5 with total profit = 27 + 100 + 15 = 142


Complexity Analysis

PhaseOperationComplexity
Sorting jobs by profitComparison sortO(n log n)
Selecting and inserting each jobInner while loop (at most k iterations per job)O(n²) in worst case
  • The outer loop runs n times.
  • The inner while loop and shifting loop together run at most O(n) per iteration.
  • Therefore, the overall time complexity is:

$$T(n) = O(n^2)$$

The dominant term is the job insertion step, making the overall complexity O(n²).


Summary

AspectDetail
StrategyGreedy (highest profit first)
Key IdeaSchedule each job in latest available slot before deadline
Time ComplexityO(n²)
OptimalityGives optimal (maximum profit) feasible schedule

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.