Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each 1 <= i <= n job is given by two numbers d(i) and p(i), where d(i) is th

ID: 3718909 • Letter: F

Question

For each 1 <= i <= n job is given by two numbers d(i) and p(i), where d(i) is the deadline and p(i) is the penalty. The length of each job is equal to 1 minute and once the job starts it cannot be stopped until completed. We want to schedule all jobs, but only one job can run at any given time. If job i does not complete on or before its deadline, we will pay its penalty p(i). Design a greedy algorithm to find a schedule such that all jobs are completed and the sum of all penalties is minimized. What is the running time of your algorithm?

Explanation / Answer

Solution:

The algorithm is given below:

Algorithm:

Running time:

The above algorithm is sorting the given array based on the penalty and also based on the deadline, which will take n log n time each

after that, we are assigning the job in O(n) time

so the time complexity will be

T(n)= O(n log n).

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote