Ask Question
27 September, 20:49

Each of the n projects must be completed in the next D days or you lose its contract. Unfortunately, you do not have enough time to complete all the projects. Your goal is to select a subset S of the projects to complete that will maximize the total fees you earn in D days.

+3
Answers (1)
  1. 27 September, 22:56
    0
    The best algorithm to follow here will be the Greedy algorithm.

    •We have to generate subsets of the jobs and check them all.

    •We also have to keep track of the maximum profit.

    •That is we take the best local solution first.

    •That is why the greedy algorithm is a good fit for this job.

    Description and Pseudo Code>>

    •First, we have to sort all the jobs in decreasing order of the profit.

    •Second, we have to initialize the result sequence as the first job in the sorted jobs section.

    •Now if the current job can be fitted in the deadline, then it is added to the result otherwise ignore it.

    Pseudo Code>.

    printJobSchedule (jobs) {

    sort (arr); / /sort all the jobs in decreasing order

    for all the given jobs do

    find a free slot for the job

    if free slot found then

    add the job to result

    slot = = full

    end if

    end

    Time Complexity of the algorithm is >>

    O (n^2)

    This can be further optimized by using disjoint set.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Each of the n projects must be completed in the next D days or you lose its contract. Unfortunately, you do not have enough time to ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers