# You are given a list of jobs where each job has a start time, finish time, and the profit associated with that job, find the maximum profit subset of non-overlapping jobs

### All Answers

total answers (1)

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSID2ht6034qqccj06tinqm1rovnkblq514b): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

total answers (1)

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0

1) Recursive Approach:In this approach we will use recursion, we will create a structure of job which will have three variable

st,enandprwhich will havestis equal to start,enis the end andprwill be profit.There are two possibilities for each job, either that job is included in the overall profit or otherwise, it is not included.

If that job is included in overall profit-making then we have to recur for those jobs which do not make any conflict with the selected job, so we make a find function which will take vector and index as a parameter and return the index of non-conflict job.

In order to find the index of the job index which do not make any intersection with the current selected job, we can also use a binary search method to reduce the time complexity.

The second possibility with the current job is that the selected job is not included in the overall profit.

Time Complexityfor the above approach in the worst case isexponentialSpace complexityfor the above approach isO(n)2) Dynamic Programming Approach:In this approach we will use memoization technique, we will create a dp[] state, each time we make a recursive call

we store that result in the

dp[]state, we will initialize alldp[]state with -1, if thedp[]is -1 then it means that has not been calculated so we need to calculate it and if it is not -1 then we will directly return it.Time Complexityfor the above approach in the worst case is:O(n*n)Space complexityfor the above approach in the worst case is:O(n)C++ Implementation (Recursive Approach):Output:C++ Implementation (Dynamic Programming Approach):Output: