Commit Graph

221 Commits

Author SHA1 Message Date
pre-commit-ci[bot]
421ace81ed
[pre-commit.ci] pre-commit autoupdate (#9013)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.285 → v0.0.286](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.285...v0.0.286)
- [github.com/tox-dev/pyproject-fmt: 0.13.1 → 1.1.0](https://github.com/tox-dev/pyproject-fmt/compare/0.13.1...1.1.0)

* updating DIRECTORY.md

* Fis ruff rules PIE808,PLR1714

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-08-29 15:18:10 +02:00
AmirSoroush
b3dc6ef035
fixes #9002; improve insertion_sort algorithm (#9005)
* fixes #9002; improve insertion_sort algorithm

* add type hints to sorts/insertion_sort.py
2023-08-21 16:17:02 -07:00
Boris Galochkin
72c7b05caa
Fix sorts/bucket_sort.py implementation (#5786)
* Fix sorts/bucket_sort.py

* updating DIRECTORY.md

* Remove unused var in bucket_sort.py

* Fix list index in bucket_sort.py

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-08-17 18:38:19 -07:00
Dylan Buchi
90a8e6e0d2
Update sorts/bubble_sort.py (#5802)
* Add missing type annotations in bubble_sort.py

* Refactor bubble_sort function
2023-07-31 11:50:00 -07:00
Christian Clauss
4b79d771cd
Add more ruff rules (#8767)
* Add more ruff rules

* Add more ruff rules

* pre-commit: Update ruff v0.0.269 -> v0.0.270

* Apply suggestions from code review

* Fix doctest

* Fix doctest (ignore whitespace)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-26 09:34:17 +02:00
shricubed
44aa17fb86
Working binary insertion sort in Python (#8024) 2023-05-11 06:50:32 +12:00
Christian Clauss
c96241b5a5
Replace bandit, flake8, isort, and pyupgrade with ruff (#8178)
* Replace bandit, flake8, isort, and pyupgrade with ruff

* Comment on ruff rules

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-03-15 13:58:25 +01:00
Christian Clauss
64543faa98
Make some ruff fixes (#8154)
* Make some ruff fixes

* Undo manual fix

* Undo manual fix

* Updates from ruff=0.0.251
2023-03-01 17:23:33 +01:00
Jan Wojciechowski
1bf03889c5
Update bogo_sort.py (#8144) 2023-02-20 11:14:01 +13:00
Christian Clauss
c909da9b08
pre-commit: Upgrade psf/black for stable style 2023 (#8110)
* pre-commit: Upgrade psf/black for stable style 2023

Updating https://github.com/psf/black ... updating 22.12.0 -> 23.1.0 for their `2023 stable style`.
* https://github.com/psf/black/blob/main/CHANGES.md#2310

> This is the first [psf/black] release of 2023, and following our stability policy, it comes with a number of improvements to our stable style…

Also, add https://github.com/tox-dev/pyproject-fmt and https://github.com/abravalheri/validate-pyproject to pre-commit.

I only modified `.pre-commit-config.yaml` and all other files were modified by pre-commit.ci and psf/black.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-02-01 18:44:54 +05:30
Maxim Smolskiy
79ef431cec
Reduce the complexity of sorts/merge_insertion_sort.py (#7954)
* Reduce the complexity of sorts/merge_insertion_sort.py

* Add tests

* Lower the --max-complexity threshold in the file .flake8
2022-12-24 15:57:28 +01:00
Mark Mayo
f32d611689
clean of unnecessary checks, imports, calls (#7993) 2022-11-21 00:00:27 +13:00
Dhruv Manilawala
3bf86b91e7
fix: no implicit optional (#7984) 2022-11-15 14:55:14 +01:00
samyakpagariya
fcfe35c3d8
For the better understanding of time taken. (#6583)
* For the better understanding of time taken.

In this change I have initialized a variable p with the value of (1e9+7) and then took the modulus of process time with it . This modification gives better time taken by the process . Firstly it was giving answer in the exponential now it gives in the integer form.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Apply suggestions from code review

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
2022-10-30 11:43:41 +01:00
Sushant Srivastav
5ba5c54858
Updated info (#7866)
* Updated info

Updated the readme section for sorts.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update sorts/README.md

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update README.md

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-30 10:08:54 +01:00
Andrey
cf08d9f5e7
Format docs (#7821)
* Reformat docs for odd_even_sort.py

* Fix docstring formatting

* Apply suggestions from code review

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
2022-10-29 08:26:19 +02:00
Caeden Perelli-Harris
61eedc16c3
Remove useless code in doctests (#7733)
* refactor: Fix matrix display deprecation

* refactor: Remove useless `print` and `pass` statements

* revert: Replace broken doctests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* revert: Fix failing doctests

* chore: Satisfy pre-commit

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-27 22:52:00 +02:00
Caeden Perelli-Harris
9bba42eca8
refactor: Indent ... for visual purposes (#7744) 2022-10-27 19:42:30 +02:00
Caeden
c6582b35bf
refactor: Move constants outside of variable scope (#7262)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-16 15:03:29 +05:30
Caeden
a652905b60
Add Flake8 comprehensions to pre-commit (#7235)
* ci(pre-commit): Add ``flake8-comprehensions`` to ``pre-commit`` (#7233)

* refactor: Fix ``flake8-comprehensions`` errors

* fix: Replace `map` with generator (#7233)

* fix: Cast `range` objects to `list`
2022-10-15 19:29:42 +02:00
Caeden
6e69181d1f
refactor: Replace list() and dict() calls with literals (#7198) 2022-10-15 06:37:03 +05:30
Caeden
4d0c830d2c
Add flake8 pluin flake8 bugbear to pre-commit (#7132)
* ci(pre-commit): Add ``flake8-builtins`` additional dependency to ``pre-commit`` (#7104)

* refactor: Fix ``flake8-builtins`` (#7104)

* fix(lru_cache): Fix naming conventions in docstrings (#7104)

* ci(pre-commit): Order additional dependencies alphabetically (#7104)

* fix(lfu_cache): Correct function name in docstring (#7104)

* Update strings/snake_case_to_camel_pascal_case.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update data_structures/stacks/next_greater_element.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update digital_image_processing/index_calculation.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update graphs/prim.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update hashes/djb2.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* refactor: Rename `_builtin` to `builtin_` ( #7104)

* fix: Rename all instances (#7104)

* refactor: Update variable names (#7104)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* ci: Create ``tox.ini`` and ignore ``A003`` (#7123)

* revert: Remove function name changes (#7104)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename tox.ini to .flake8

* Update data_structures/heap/heap.py

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>

* refactor: Rename `next_` to `next_item` (#7104)

* ci(pre-commit): Add `flake8` plugin `flake8-bugbear` (#7127)

* refactor: Follow `flake8-bugbear` plugin (#7127)

* fix: Correct `knapsack` code (#7127)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-13 18:03:06 +02:00
Caeden
d5a9f649b8
Add flake8-builtins to pre-commit and fix errors (#7105)
Ignore `A003`

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-13 19:53:59 +05:30
Caeden
07e991d553
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038)

* refactor: Fix naming conventions (#7038)

* Update arithmetic_analysis/lu_decomposition.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038)

* chore: Fix naming conventions in doctests (#7038)

* fix: Temporarily disable project euler problem 104 (#7069)

* chore: Fix naming conventions in doctests (#7038)

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-13 00:54:20 +02:00
Jérome Eertmans
8cce0d463a
refactor: pivot is randomly chosen (#6643)
As described in #6095, this reduces the chances to observe a O(n^2) complexity.

Here, `collection.pop(pivot_index)` is avoided for performance reasons.

Fixes: #6095
2022-10-05 11:32:07 +01:00
Debjit Bhowal
a12e6941a6
Fix docstring (#6461)
* fixed wrong algo name to radix sort

* added wiki url

* Added "source" in docstring

* Update radix_sort.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-01 14:17:15 +02:00
Satish Mishra
45d3eabeb5
Add Optimized Shell Sort (#6225)
* Add Optimized Shell Sort

* Added return type

* reformatted

* added shrink_shell.py

* ran directory generator

* Rename shrink_shell.py to shrink_shell_sort.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-09-14 09:43:08 +01:00
KanakalathaVemuru
e1e7922efa
Add circle sort implementation (#5548)
* Added circle sort implementation

* Added modifications

* Added modifications

* Update circle_sort.py

* Update circle_sort.py

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-07-17 05:42:58 +08:00
dangbb
5bac76d7a5
Fix iter_merge_sort bug (#6153)
* Fixed bug where array length 2 can't be sorted

* Add MCC and DU path test

Add test to conversions/octal_to_decimal.py and sorts\iterative_merge_sort.py

* ""

* Update octal_to_decimal.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-05-21 22:02:53 +08:00
Omkaar
dbee5f072f
Improve code on f-strings and brevity (#6126)
* Update strassen_matrix_multiplication.py

* Update matrix_operation.py

* Update enigma_machine2.py

* Update enigma_machine.py

* Update enigma_machine2.py

* Update rod_cutting.py

* Update external_sort.py

* Update sol1.py

* Update hill_cipher.py

* Update prime_numbers.py

* Update integration_by_simpson_approx.py
2022-05-13 20:51:44 +08:00
eee555
bbb88bb5c2
Fix bug in bucket_sort.py (#6005) 2022-05-13 04:28:51 +08:00
varopxndx
10d0e4ecbf
docs: Fix quicksort & binary tree traversal doc (#4878)
* Fix quicksort doc

* add binary tree traversals doc

* Add link to the reference

* Fix job

* Change url

* Update binary_tree_traversals.md

* Update normal_distribution_quick_sort.md

* Update normal_distribution_quick_sort.md

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-04-29 01:05:21 +08:00
yellowsto
6680e435a7
Update merge_insertion_sort.py (#5833)
* Update merge_insertion_sort.py

Fixes #5774

merge_insertion_sort

Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>

* Update merge_insertion_sort.py

Fixes #5774

merge_insertion_sort

Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>

* Update merge_insertion_sort.py

Fixes #5774

added permutation range from 0 to 4

Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>

* Use `all()`

Co-authored-by: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
2021-12-16 17:27:15 +08:00
Connor Bottum
31061aacf2
fix: use += in sorts/recursive_mergesort_array.py (#5019) 2021-10-27 00:43:46 +08:00
Manan Rathi
50485f7c8e
Fix typos in Sorts and Bit_manipulation (#4949)
* Fix several typos

* Update bit_manipulation/README.md

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Update double_sort.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2021-10-20 16:42:32 +08:00
Sarvesh Kumar Dwivedi
90db98304e
Fix word typos in comments (#4928)
* fixed: spelling

nonegative -> non-negative

* fixed: spelling

transpostiion -> transposition

* fixed: spelling

topolical -> topological

* fixed: spelling

sufix -> suffix
2021-10-04 12:07:58 +08:00
Nolan Emirot
d530d2bcf4
fix: comment in patience sort (#4972) 2021-10-04 11:33:42 +08:00
Christian Clauss
cecf43d648
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-09-07 13:37:03 +02:00
Kiran Hipparagi
757d4fb84f
Added Dutch National Flag algorithm #4636 (#4639)
* Added Dutch national flag sort Algorithm

* Changed file name to dnf_sort.py

* Added descriptive name and type hint 

Added descriptive name and type hint  for parameter with doctest for the function dnf_sort.

* Added test cases

* Added doctest cases

* Update sorts/dnf_sort.py

* Added doctest for dutch_national_flag_sort sorts/dnf_sort.py

* Update sorts/dnf_sort.py

* Added doctest for the function
dutch_national_flag_sort

* update file as per black code formatter

* Update dnf_sort.py

* Update and rename dnf_sort.py to dutch_national_flag_sort.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-08-31 22:06:49 +02:00
Bonnie
032999f36e
Create exchange_sort.py (#4600)
* Create exchange_sort.py

added exchange sort

* Fixed doctest in exchange_sort.py

* Fixed formatting error and added new length variable

added empty line at end of exchange_sort.py and turned len(numbers) into a variable

* Fixed formatting errors with black

added empty line
2021-08-15 07:43:05 +02:00
Benjamin Fein
650039a279
Add a recursive merge sort algorithm that accepts an array as input. (#4462)
This is a different recursive implementation of the merge sort algorithm.

* Recursive Merge Sort That Accepts an Array 

Recursive Merge Sort That Accepts an Array

* Add Wikipedia Link

* Fixes naming conventions

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Adds black format

* Removes unused variables

* Fixes variable names and adds documentation

* Fixes variable names to use snake_case.

* Removes double #.

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Benjamin Fein <benfein78@icloud.com>
2021-05-30 10:27:42 -05:00
Tobias
b913a0d83a
Implemented MSD radix sort algorithm in-place (#4449)
* Implemented MSD radix sort algorithm inplace

* Fixed formatting
2021-05-24 22:36:57 +02:00
Tobias
b11e5314b7
Added implementation for MSD radix sort algorithm based on binary representation (#4441)
* Added MSD radix sort algorithm

* Fixed typos

* Added doctests

* Added link to wikipedia

* Added doctest and improved code
2021-05-20 21:15:51 +02:00
杜远超
67b33a295b
Optimization shell sort (#4119)
* optimization

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-02-26 09:01:50 +08:00
Matthew
a4726ca248
[mypy]Correction of all errors in the sorts directory (#4224)
* [mypy] Add/fix type annotations for recursive_insertion_sort(#4085)

* [mypy] Add/fix type annotations for bucket_sort(#4085)

* [mypy] Reworked code for cocktail_shaker_sort so that missing return statement error is resolved(#4085)

* [mypy] Add/fix type annotations for patience_sort(#4085)

* [mypy] Add/fix type annotations for radix_sort(#4085)

Co-authored-by: goodm2 <4qjpngu8mem8cz>
2021-02-23 10:02:30 +01:00
Matthew
81c46dfd55
[mypy] Add/fix type annotations for quick_sort(#4085) (#4215)
Co-authored-by: goodm2 <4qjpngu8mem8cz>
2021-02-20 23:10:23 +01:00
MarineJoker
78ddb46066
Quick sort with lomuto partition (#3875)
* add quick sort algorithm with Lomuto partition

* fix(lomuto_partition): fix snake_case
2021-02-17 15:28:50 +01:00
Ocean Monjur
f66325a01b
odd_even_sort.py (#4199)
* odd_even_sort.py

* Update odd_even_sort.py

* Update odd_even_sort.py
2021-02-11 17:49:53 +01:00
Abdeldjaouad Nusayr Medakene
4903a65779
Create slowsort.py (#3865)
* Create slowsort.py

added slowsort algorithm implementation to sorts

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py

* Update slowsort.py
2021-02-09 17:13:48 +01:00
Du Yuanchao
53371b2381
Optimization for shell sort (#4038)
* fixed shell sort

* udpate code style

* Update sorts/shell_sort.py

Co-authored-by: John Law <johnlaw.po@gmail.com>

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-12-18 10:39:51 +01:00