Python icon indicating copy to clipboard operation
Python copied to clipboard

Add Optimized Shell Sort

Open ZicsX opened this issue 3 years ago • 3 comments

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"""

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

Checklist:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x] All new Python files are placed inside an existing directory.
  • [x] All filenames are in all lowercase characters with no spaces or dashes.
  • [x] All functions and variable names follow Python naming conventions.
  • [x] All function parameters and return values are annotated with Python type hints.
  • [x] All functions have doctests that pass the automated testing.
  • [x] 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}.

ZicsX avatar Jun 29 '22 13:06 ZicsX

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 avatar Jul 03 '22 17:07 poyea

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

poyea avatar Jul 08 '22 06:07 poyea

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[bot] avatar Aug 13 '22 14:08 stale[bot]