Skip to content

fix: Correct SJF scheduling logic for arrived-process selection#3192

Open
harshitrajput2802 wants to merge 1 commit into
TheAlgorithms:masterfrom
harshitrajput2802:fix-sjf-bug
Open

fix: Correct SJF scheduling logic for arrived-process selection#3192
harshitrajput2802 wants to merge 1 commit into
TheAlgorithms:masterfrom
harshitrajput2802:fix-sjf-bug

Conversation

@harshitrajput2802

Copy link
Copy Markdown

Description of Change

Corrected the implementation of the non-preemptive Shortest Job First (SJF) CPU scheduling algorithm by ensuring that only processes that have already arrived are eligible for scheduling. The previous implementation selected processes solely based on burst time, which could allow processes to execute before their arrival.

This update also:

  • Reworked the scheduling logic using an arrival-ordered process list and a ready queue prioritized by burst time.
  • Added deterministic tie-breaking based on arrival time and process ID.
  • Added an independent O(n²) reference implementation for verification.
  • Expanded self-tests with both regression and randomized test cases to validate correctness.
  • Improved documentation with comprehensive Doxygen comments and organized the implementation within the scheduling::non_preemptive_sjf namespace.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Fixes the non-preemptive SJF scheduling logic to consider only arrived processes and strengthens verification with an independent reference implementation and regression tests.

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.

1 participant