Skip to content

fix: use input-length phases in parallel odd-even transposition sort - #15554

Draft
mohammmad357 wants to merge 2 commits into
TheAlgorithms:masterfrom
mohammmad357:fix-parallel-sort-phase-count
Draft

mohammmad357 wants to merge 2 commits into
TheAlgorithms:masterfrom
mohammmad357:fix-parallel-sort-phase-count

Conversation

@mohammmad357

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

The parallel odd-even transposition worker always performs ten phases. A
reverse-ordered eleven-item list therefore returns
[1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 10] instead of list(range(11)).
Pass the input length to every worker and perform that many phases, matching
the existing comment and the odd-even sorting network's bound.

Refs #10925 (closed). @gyan313 previously identified and proposed this phase
count approach in closed, unmerged #10976; credit for that earlier observation
and approach belongs to them. This patch only carries the phase count through
the existing worker arguments. Empty/singleton input handling and typing
refactors remain outside this diff.

I checked the open parallel-sort PRs #15493, #15513, #15531 and #15538:
their patches retain the ten-phase loop. This addresses a separate correctness
case, although changes to the same file may conflict if another PR lands first.
It does not resolve the whole comparable-types umbrella #15234.

Validation

  • Upstream base: 215c1f0710f610aaf5ebaeab04edacec3f5308cd, branch
    fix-parallel-sort-phase-count; exactly one algorithm file changed.
  • Reproduced the eleven-item failure before the fix on Windows 10 / Python 3.13.7.
  • After the fix, eight independent comparisons with Python sorted passed:
    reverse inputs of lengths 2, 3, 10, 11 and 12, twelve strings, fifteen seeded
    duplicate/negative integers and twenty seeded floats. All returned the same
    input list object. These checks use a standalone spawn-safe harness.
  • All ten existing doctests passed; doctests are unchanged in this PR.
  • git diff --check passed.
  • Local Ruff/pre-commit could not run: installing their tools from PyPI timed
    out on files.pythonhosted.org; python -m pre_commit run --all-files
    reports No module named pre_commit. Python 3.15t was not tested locally.
    Leaving this as a draft until upstream CI and maintainer review are available;
    local correctness is not claimed to replace those checks.

Prepared with AI coding assistance; no outside user feedback or ratings are
claimed. The earlier contributor is explicitly credited above.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory. (No new files.)
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue numbers with a closing keyword.

Unchecked items: this builds on the credited earlier approach; existing
unannotated parameters and worker doctest coverage are preserved; no new
algorithm or complete open issue is resolved. The newly added phases
parameter has an int annotation.

This branch has not been deployed

No deployments
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