
- Data Structures & Algorithms
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- Algorithm
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- DSA - Greedy Algorithms
- DSA - Divide and Conquer
- DSA - Dynamic Programming
- Data Structures
- DSA - Data Structure Basics
- DSA - Array Data Structure
- Stack & Queue
- DSA - Stack
- DSA - Expression Parsing
- DSA - Queue
- Searching Techniques
- DSA - Linear Search
- DSA - Binary Search
- DSA - Interpolation Search
- DSA - Hash Table
- Sorting Techniques
- DSA - Sorting Algorithms
- DSA - Bubble Sort
- DSA - Insertion Sort
- DSA - Selection Sort
- DSA - Merge Sort
- DSA - Shell Sort
- DSA - Quick Sort
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Spanning Tree
- DSA - Heap
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Job Sequencing Problem with Deadlines
In this problem, there is a list of jobs given. In the list, the deadline and the profits are also given for each job. Every job will take a single unit of time, so the minimum deadline for a job is 1. If only one job can be scheduled at a time, then maximize the profit.
To solve this problem, all subset of the set of jobs are generated to check whether the individual subset is feasible or not. Also, keep track on maximum profit for all feasible subset that has generated.
The time complexity of this algorithm is O(n^2)
Input and Output
Input: A list of jobs with job id, deadline and profit. And the number of jobs n. {('a', 2, 100), ('b', 1, 19), ('c', 2, 27), ('d', 1, 25), ('e', 3, 15)} n = 5 Output: Following is maximum profit sequence of job sequence: c a e
Algorithm
jobSequence(jobList, n)
Input − The list of jobs and the number of jobs present in the list.
Output − The sequence, how jobs are taken.
Begin sort the jobs in jobList according to their profit create a list of job sequence and slot to track free time slots initially make all slots are free for all given jobs i do for all jobs in the list from ending of the list do if slot[j] is free then jobSequence[j] := i make slot[j] := fill break the loop done done for all slots when it is not free do print id of job using jobList[jobSequence[i]] done End
Example
#include<iostream> #include<algorithm> using namespace std; struct Job { char id; int deadLine; int profit; }; bool comp(Job j1, Job j2) { return (j1.profit > j2.profit); //compare jobs based on profit } int min(int a, int b) { return (a<b)?a:b; } void jobSequence(Job jobList[], int n) { sort(jobList, jobList+n, comp); //sort jobList on profit int jobSeq[n]; // To store result (Sequence of jobs) bool slot[n]; // To keep track of free time slots for (int i=0; i<n; i++) slot[i] = false; //initially all slots are free for (int i=0; i<n; i++) { //for all given jobs for (int j=min(n, jobList[i].deadLine)-1; j>=0; j--) { //search from last free slot if (slot[j]==false) { jobSeq[j] = i; // Add this job to job sequence slot[j] = true; // mark this slot as occupied break; } } } for (int i=0; i<n; i++) if (slot[i]) cout << jobList[jobSeq[i]].id << " "; //display the sequence } int main() { Job jobList[] = {{'a',2,100}, {'b',1,19}, {'c',2,27},{'d',1,25},{'e',3,15}}; int n = 5; cout << "Following is maximum profit sequence of job sequence: "; jobSequence(jobList, n); }
Output
Following is maximum profit sequence of job sequence: c a e
- Related Articles
- What is Microprogram Sequencing?
- What is Address Sequencing in Computer Architecture?
- Can I get a job with a Python certificate?
- Weighted Job Scheduling
- Job Satisfaction Theories
- Peterson’s Problem
- Partition problem
- The Linux Job Market
- Job Design: Meaning & Significance
- How can we approach the problem of clustering with obstacles?
- Critical Section Problem
- Readers-Writers Problem
- Activity Selection Problem
- Fractional Knapsack Problem
- M-Coloring Problem

Advertisements