written 8.0 years ago by | • modified 8.0 years ago |
Let n=5, {P1, P2, P3, P4, P 5} = {20, 15, 10, 5, 3} & {d1, d2, d3, d4, d5} = {2, 2, 1, 3, 3}
Step: 1
We will arrange the profits Pi in descending order, along with corresponding deadlines.
Step: 2
Create an array J [] which stores the jobs. Initially j [] will be
Step: 3
Add ith Job in array J [ ] at index denoted by its deadlines Di
First Job is P1, its deadline is 2.
Hence insert P1 in the array J [] at 2nd index.
Step: 4
Next Job is P2 whose deadline is 2 but J[2] is already occupied. We will search for empty location < J [2]. The J [1] is empty. Insert P2 at J [1].
Step: 5
Next Job P3 whose deadline is 1. But as J[1] is already occupied discard this job.
Step: 6
Next job is P4 with deadline 3. Insert P4 at J [3].
Step: 7
Next Job is P5 with deadline 3, but as there is empty slot at < = J [3], we will discard this job.
Step: 8
Thus the optimal sequence which we will obtain will be P2 – P1 – P4. The Maximum profit will be 40.