Skip to content

Commit af31df0

Browse files
authored
Create README.md
1 parent 004ca98 commit af31df0

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Job Sequencing Problem using Greedy Approach
2+
🔴 Language used : **Python 3**
3+
4+
## 🎯 Aim
5+
The aim of this script is to find the maximum profit earned by executing the tasks within the specified deadlines.
6+
7+
## 👉 Purpose
8+
The main purpose of this script is to show the implementation of Greedy Approach to find the maximum profit earned by executing the tasks within the specified deadlines.
9+
10+
## 📄 Description
11+
Given an array of jobs where every job has a deadline and associated profit if the job is finished before the deadline. It is also given that every job takes a single unit of time, so the minimum possible deadline for any job is 1. Maximize the total profit if only one job can be scheduled at a time.
12+
13+
🔴 Examples:
14+
15+
```
16+
Constraints:
17+
arr[] -> Set of datapoints including JobID, Deadline and Profit into a single array.
18+
t -> No. of jobs to be scheduled.
19+
20+
Input:
21+
Five Jobs with following deadlines and profits
22+
23+
JobID Deadline Profit
24+
a 2 100
25+
b 1 19
26+
c 2 27
27+
d 1 25
28+
e 3 15
29+
30+
Output:
31+
Following is maximum profit sequence of jobs:
32+
c, a, e
33+
```
34+
35+
36+
## 🧮 Algorithm
37+
Greedily choose the jobs with maximum profit first, by sorting the jobs in decreasing order of their profit. This would help to maximize the total profit as choosing the job with maximum profit for every time slot will eventually maximize the total profit.
38+
- This problem is basically solved using the `printJobScheduling(arr, t)` funtion, which is basically the main function. `arr` signifies the job array and `t` signifies the number of jobs to be scheduled.
39+
- Sort all jobs in decreasing order of profit.
40+
- Iterate on jobs in decreasing order of profit.For each job , do the following :
41+
- Find a time slot `i`, such that slot is empty and `i < deadline` and `i` is greatest. Put the job in this slot and mark this slot filled.
42+
- If no such `i` exists, then ignore the job.
43+
- This whole process will be repeated until and unless the funtion got the `-1` value. Once it got the `-1` value it will stop the program and provide the output.
44+
45+
## 💻 Input and Output
46+
- **Test Case 1 :**
47+
```
48+
Input Given :
49+
arr = [['a', 2, 100],
50+
['b', 1, 19],
51+
['c', 2, 27],
52+
['d', 1, 25],
53+
['e', 3, 15]]
54+
```
55+
56+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Job%20Sequencing%20Problem/Images/jsp-1.png)
57+
58+
- **Test Case 2 :**
59+
```
60+
Input Given :
61+
arr = [['a', 4, 20],
62+
['b', 1, 10],
63+
['c', 1, 40],
64+
['d', 1, 30]]
65+
```
66+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Job%20Sequencing%20Problem/Images/jsp-2.png)
67+
68+
## ⏰ Time and Space complexity
69+
- **Time Complexity :** `O(n^2)`.
70+
- **Space Complexity :** `O(n)`.
71+
72+
---------------------------------------------------------------
73+
## 🖋️ Author
74+
**Code contributed by, _Abhishek Sharma_, 2022 [@abhisheks008](github.com/abhisheks008)**
75+
76+
[![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/)

0 commit comments

Comments
 (0)