Skip to content

Add Optimized Shell Sort #6225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 14, 2022
Merged

Conversation

ZicsX
Copy link
Contributor

@ZicsX ZicsX commented Jun 29, 2022

Describe your change:

Added a new shell sort implementation which is slightly faster than its pure implementation.

This shell sort is implemented using a gap, which shrinks by a certain factor each iteration. In this implementation, the gap is initially set to the length of the collection. The gap is then reduced by a certain factor (1.3) each iteration.

For each iteration, the algorithm compares elements that are a certain number of positions apart (determined by the gap). If the element at the higher position is greater than the element at the lower position, the two elements are swapped. The process is repeated until the gap is equal to 1.

The reason this is more efficient is that it reduces the number of comparisons that need to be made.
By using a smaller gap, the list is sorted more quickly.

image"""

  • Add an algorithm?
  • Documentation change?
  • Fix a bug or typo in an existing algorithm?

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.
  • 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 have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added the require type hints https://docs.python.org/3/library/typing.html label Jun 29, 2022
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Jun 29, 2022
@ghost ghost removed the require type hints https://docs.python.org/3/library/typing.html label Jun 29, 2022
@ghost ghost added tests are failing Do not merge until tests pass awaiting reviews This PR is ready to be reviewed and removed awaiting reviews This PR is ready to be reviewed labels Jun 29, 2022
@ZicsX ZicsX requested a review from l3str4nge June 30, 2022 12:38
@ZicsX ZicsX force-pushed the shrink-shell-sort branch from 85f4692 to d7eb29e Compare June 30, 2022 21:44
Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request!🤩

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Jul 3, 2022
@poyea
Copy link
Member

poyea commented Jul 3, 2022

2022-07-03T16:34:40.6973928Z ==================================== ERRORS ====================================
2022-07-03T16:34:40.6974259Z _______________ ERROR collecting quantum/ripple_adder_classic.py _______________
2022-07-03T16:34:40.6974616Z quantum/ripple_adder_classic.py:6: in <module>
2022-07-03T16:34:40.6975140Z     from qiskit.providers import BaseBackend
2022-07-03T16:34:40.6975800Z E   ImportError: cannot import name 'BaseBackend' from 'qiskit.providers' (/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/site-packages/qiskit/providers/__init__.py)
2022-07-03T16:34:40.6976280Z =============================== warnings summary ===============================

Seems unrelated.

@poyea poyea self-assigned this Jul 3, 2022
@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Jul 4, 2022
@poyea
Copy link
Member

poyea commented Jul 8, 2022

@ZicsX You may merge the main branch again because of 9135a1f

@stale
Copy link

stale bot commented Aug 13, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Aug 13, 2022
@stale stale bot removed the stale Used to mark an issue or pull request stale. label Sep 14, 2022
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 14, 2022
@poyea poyea merged commit 45d3eab into TheAlgorithms:master Sep 14, 2022
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Sep 14, 2022
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.

3 participants