Skip to content

feat: add job sequencing algorithm#1038

Merged
siriak merged 3 commits intoTheAlgorithms:masterfrom
AliAlimohammadi:add-job-sequencing
Apr 24, 2026
Merged

feat: add job sequencing algorithm#1038
siriak merged 3 commits intoTheAlgorithms:masterfrom
AliAlimohammadi:add-job-sequencing

Conversation

@AliAlimohammadi
Copy link
Copy Markdown
Contributor

@AliAlimohammadi AliAlimohammadi commented Apr 24, 2026

Description

Adds a greedy Job Sequencing algorithm to src/greedy/.

Given a set of jobs each with a deadline and a profit, the algorithm schedules at most one job per time-slot to maximize total profit. Jobs not completed on or before their deadline earn nothing.

Greedy strategy:

  1. Sort all jobs by profit in descending order.
  2. For each job (highest profit first), find the latest free time-slot at or before the job's deadline and assign the job there.
  3. Return the scheduled jobs in time-slot order along with the total profit.

Placing each job in the latest available slot is the key greedy choice — it keeps earlier slots open for jobs with tighter deadlines.

Complexity: $O(n \cdot D)$ time, $O(\min(n, D))$ space, where $D$ is the maximum deadline. The slot array is capped at $\min(n, D)$ since at most $n$ jobs can ever be scheduled, preventing large allocations when $D \gg n$.

References:

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@AliAlimohammadi
Copy link
Copy Markdown
Contributor Author

@siriak, this is ready to be merged.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.96%. Comparing base (3bccfa8) to head (efcd035).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1038      +/-   ##
==========================================
+ Coverage   95.94%   95.96%   +0.01%     
==========================================
  Files         392      393       +1     
  Lines       29806    29919     +113     
==========================================
+ Hits        28597    28711     +114     
+ Misses       1209     1208       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new greedy “Job Sequencing with deadlines” implementation under src/greedy/ and exposes it through the greedy module index and the repo’s algorithm directory listing.

Changes:

  • Added schedule_jobs API plus Job / ScheduleResult types and unit tests.
  • Exported the new module/types from src/greedy/mod.rs.
  • Added an entry to DIRECTORY.md for discoverability.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/greedy/mod.rs Registers the new module and re-exports its public API.
src/greedy/job_sequencing.rs Implements the greedy job sequencing algorithm + tests and docs.
DIRECTORY.md Adds a link to the new greedy algorithm source file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/greedy/job_sequencing.rs Outdated
Comment thread src/greedy/job_sequencing.rs Outdated
Comment thread src/greedy/job_sequencing.rs Outdated
Comment thread src/greedy/job_sequencing.rs Outdated
@siriak
Copy link
Copy Markdown
Member

siriak commented Apr 24, 2026

Please check the comments, see if they are relevant

Copy link
Copy Markdown
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit c4c395f into TheAlgorithms:master Apr 24, 2026
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-job-sequencing branch April 24, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants