GreedyAnimated
Job Sequencing with Deadlines
Do the highest-profit jobs, each in the latest free slot before its deadline.
Time
O(n log n)
Extra space
O(n)
Use it for
Scheduling for maximum profit.
How it works
- Each job takes one time slot and must finish by its deadline to earn its profit.
- Consider jobs from highest profit to lowest.
- Put each job in the latest free slot at or before its deadline (this keeps earlier slots open for tighter jobs). If no slot is free, drop the job.
- O(n log n) with sorting (O(n²) with the plain slot scan shown here).
Watch it run
Loading animation…