Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Job Sequencing Problem | Greedy Algorithms: Overview and Examples
Greedy Algorithms using Python
course content

Contenido del Curso

Greedy Algorithms using Python

Greedy Algorithms using Python

1. Greedy Algorithms: Overview and Examples
2. Greedy on Arrays
3. Greedy on Graphs

Job Sequencing Problem

Scheduling can be tough sometimes, and the Job Sequencing Problem is an example. You have a list of jobs with some deadlines and profit that you’ll receive if you finish the job before the deadline. Your goal is to reach the maximum total profit.

Each job lasts 1-time point, and you can do no more than one job at the moment.

This problem is similar to the Schedule Problem, but there is no maximizing the total number of tasks, only total profit.

The data is jobs – a list of dicts:

jobs[i] = {'name': “A”, 'profit':12, 'dl': 3}

Let’s be greedy and sort all jobs in decreasing order by the profit. We want to reach the maximum, so let’s pick jobs one by one and find someplace among empty slots. You can pick some empty slot between 0 and jobs[i][dl] (deadline) for jobs[i]. How to do that greedy, too?

The approach is similar to the Schedule Problem: you have to choose the rightmost empty slot, because in case if (i+1)th job has less deadline, you’ll probably find an empty slot for it.

Algorithm:

  1. Sort jobs decreasing by profit.
  2. Traverse the jobs, pick the jobs[i].
  3. If there is an empty slot[j] (j starts from jobs[i][dl] down to 0), fill it with jobs[j][name]. Else skip this job – there is no slot to schedule it.

Tarea

Complete the algorithm.

Tarea

Complete the algorithm.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 6
toggle bottom row

Job Sequencing Problem

Scheduling can be tough sometimes, and the Job Sequencing Problem is an example. You have a list of jobs with some deadlines and profit that you’ll receive if you finish the job before the deadline. Your goal is to reach the maximum total profit.

Each job lasts 1-time point, and you can do no more than one job at the moment.

This problem is similar to the Schedule Problem, but there is no maximizing the total number of tasks, only total profit.

The data is jobs – a list of dicts:

jobs[i] = {'name': “A”, 'profit':12, 'dl': 3}

Let’s be greedy and sort all jobs in decreasing order by the profit. We want to reach the maximum, so let’s pick jobs one by one and find someplace among empty slots. You can pick some empty slot between 0 and jobs[i][dl] (deadline) for jobs[i]. How to do that greedy, too?

The approach is similar to the Schedule Problem: you have to choose the rightmost empty slot, because in case if (i+1)th job has less deadline, you’ll probably find an empty slot for it.

Algorithm:

  1. Sort jobs decreasing by profit.
  2. Traverse the jobs, pick the jobs[i].
  3. If there is an empty slot[j] (j starts from jobs[i][dl] down to 0), fill it with jobs[j][name]. Else skip this job – there is no slot to schedule it.

Tarea

Complete the algorithm.

Tarea

Complete the algorithm.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 6
toggle bottom row

Job Sequencing Problem

Scheduling can be tough sometimes, and the Job Sequencing Problem is an example. You have a list of jobs with some deadlines and profit that you’ll receive if you finish the job before the deadline. Your goal is to reach the maximum total profit.

Each job lasts 1-time point, and you can do no more than one job at the moment.

This problem is similar to the Schedule Problem, but there is no maximizing the total number of tasks, only total profit.

The data is jobs – a list of dicts:

jobs[i] = {'name': “A”, 'profit':12, 'dl': 3}

Let’s be greedy and sort all jobs in decreasing order by the profit. We want to reach the maximum, so let’s pick jobs one by one and find someplace among empty slots. You can pick some empty slot between 0 and jobs[i][dl] (deadline) for jobs[i]. How to do that greedy, too?

The approach is similar to the Schedule Problem: you have to choose the rightmost empty slot, because in case if (i+1)th job has less deadline, you’ll probably find an empty slot for it.

Algorithm:

  1. Sort jobs decreasing by profit.
  2. Traverse the jobs, pick the jobs[i].
  3. If there is an empty slot[j] (j starts from jobs[i][dl] down to 0), fill it with jobs[j][name]. Else skip this job – there is no slot to schedule it.

Tarea

Complete the algorithm.

Tarea

Complete the algorithm.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Scheduling can be tough sometimes, and the Job Sequencing Problem is an example. You have a list of jobs with some deadlines and profit that you’ll receive if you finish the job before the deadline. Your goal is to reach the maximum total profit.

Each job lasts 1-time point, and you can do no more than one job at the moment.

This problem is similar to the Schedule Problem, but there is no maximizing the total number of tasks, only total profit.

The data is jobs – a list of dicts:

jobs[i] = {'name': “A”, 'profit':12, 'dl': 3}

Let’s be greedy and sort all jobs in decreasing order by the profit. We want to reach the maximum, so let’s pick jobs one by one and find someplace among empty slots. You can pick some empty slot between 0 and jobs[i][dl] (deadline) for jobs[i]. How to do that greedy, too?

The approach is similar to the Schedule Problem: you have to choose the rightmost empty slot, because in case if (i+1)th job has less deadline, you’ll probably find an empty slot for it.

Algorithm:

  1. Sort jobs decreasing by profit.
  2. Traverse the jobs, pick the jobs[i].
  3. If there is an empty slot[j] (j starts from jobs[i][dl] down to 0), fill it with jobs[j][name]. Else skip this job – there is no slot to schedule it.

Tarea

Complete the algorithm.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 6
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt