Commit Graph

166 Commits

Author SHA1 Message Date
anubhav-sharma13
ce7faa5a3a Largest subarray sum (#1404)
* Insertion_sort

* largest subarray sum

* updated print command

* removed extraspaces

* removed sys.maxint

* added explaination

* Updated function style

* Update largest_subarray_sum.py

* Update i_sort.py

* Delete bogo_bogo_sort.py
2019-10-22 09:30:11 +02:00
Sujitkumar Singh
38d7e7073a The time complexity of every algorithms make its value (#1401)
* added timer in bubble sort

* Updated time of execution

* import time in main only

* Update bubble_sort.py

* start = time.process_time()
2019-10-19 22:12:54 +02:00
ayush246
ab65a3915c Double sort (Added with required updates) (#1399)
* Added with required updates

* Updated

* required updates

* Update double_sort.py

* Update double_sort.py
2019-10-19 12:38:15 +02:00
Phyllipe Bezerra
455509acee Add Topological Sort (#1302)
* add topological sort

* fix topological sort?

* running black

* renaming file
2019-10-18 08:13:58 +02:00
Du YuanChao
e80d248e65 optimization (#1303) 2019-10-08 13:25:00 +05:00
mvhb
067a9b5136 adding input option and increasing the number of doctest (#1281)
* adding input option and incresing the number of doctest

* mixing positive and negative numbers in the same test case
2019-10-06 23:55:55 +05:00
William Zhang
9eac17a408 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
William Zhang
0e333ae021 added bogobogosort (#1258)
* added bogobogosort

* fix indentation error
2019-10-03 11:17:30 +02:00
Parth Paradkar
390feb0b23 Add doctests for sorting algorithms (#1263)
* doctests and intro docstring added

* doctests, docstrings and check for empty collection added

* Intro docstring added

* python versions reversed
2019-10-03 10:19:11 +02:00
Charitoc
2375bfbee5 Adding stooge sort (#1206)
* Adding stooge sort

* Updated doctest

* Just added underscore in the name
2019-09-26 17:19:01 +02:00
Christian Clauss
47a9ea2b0b
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python

* sort() --> sorted()
2019-08-19 15:37:49 +02:00
FrogBattle
e58a5e6842 Update tim_sort.py (#972)
* Update tim_sort.py


Update tim_sort.py

The previous algorithm was skipping numbers, according to issue #959, and my own tests.
The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.

* Update tim_sort.py
2019-07-30 18:06:48 +02:00
obelisk0114
1dc9ec8fb2 Update Bucket Sort time complexity analysis (#918) 2019-07-12 23:16:14 +08:00
Alfonso Rodríguez Pereira
5f991f7740 #315 Renamed all files to snake_case (#993) 2019-07-11 11:16:42 +02:00
cclauss
b7f13d991c Travis CI: Run black, doctest, flake8, mypy, and pytest (#964)
* Travis CI: Add type checking with mypy

* Create requirements.txt

* script: mypy --ignore-missing-stubs=cv2,numpy .

* Delete requirements.txt

* script: mypy --ignore-missing-imports .

* Run doctests

* Disable doctest -v other/detecting_english_programmatically.py

* Pytest

* No |

* pytest || true

* Run black doctest flake8 mypy pytest

* after_success: Build Directory.md

* Typo in filename: Dictionary.txt --> dictionary.txt'

Discovered via doctest run in #964

* python -m doctest -v

* pip install black flake8 mypy pytest

* pytest --doctest-glob='*.py'

* pytest --doctest-modules

* pytest --doctest-modules ./sorts

* pytest --doctest-modules ./ciphers ./other ./searches ./sorts ./strings || true

* if __name__ == "__main__":

* if __name__ == "__main__":

* if __name__ == '__main__':

* if __name__ == '__main__':

* if __name__ == '__main__':

* Create requirements.txt

* Update requirements.txt

* if __name__ == "__main__":

* Lose the doctests

* if __name__ == '__main__':

* Remove print-a-tuple

* doctest: Added missing spaces

* Update tabu_search.py

* The >>> are not doctests so change to >>)

* Travis CI: Run black, doctest, flake8, mypy, and pytest

* Link to the separate DIRECTORY.md file

* Update README.md
2019-07-08 23:27:51 +08:00
Anup Kumar Panwar
4e413c0183 Updated README 2019-07-06 11:11:20 +05:30
PatOnTheBack
217615abf6 Removed Unused Variables (#949)
- Removed two unused variables.
- Changed `a` to `_` since the `a` variable is never used.

This addresses [3 alerts from lgtm](d55bbcd204/files/sorts/Odd-Even_transposition_parallel.py).
2019-07-05 14:04:46 +05:30
Ashok Bakthavathsalam
03f9940775 Refactored to one pop() (#917) 2019-07-03 23:31:10 +08:00
PatOnTheBack
a2236cfb97 Improve Formatting and Code Quality (#934)
* Improved Formatting of basic_maths.py

- Added docstrings.
- Improved whitespace formatting.
- Renamed functions to match snake_case.

* Improved Formatting of factorial_python.py

- Added docstrings.
- Improved whitespace formatting.
- Renamed constants to match UPPER_CASE.

* Improved Formatting of factorial_recursive.py

- Improved whitespace formatting to meet PyLint standards.

* Improved Code to Conform to PyLint

- Renamed `max` to `max_num` to avoid redefining built-in 'max' [pylint]
- Removed unnecessary parens after 'while' keyword [pylint]

* Improved Formatting of factorial_recursive.py

- Added docstrings.
- Improved whitespace formatting.
2019-07-02 09:35:43 +05:30
PatOnTheBack
bd4017928e Added Whitespace and Docstring (#924)
* Added Whitespace and Docstring

I modified the file to make Pylint happier and make the code more readable.

* Beautified Code and Added Docstring

I modified the file to make Pylint happier and make the code more readable.

* Added DOCSTRINGS, Wikipedia link, and whitespace

I added DOCSTRINGS and whitespace to make the code more readable and understandable.

* Improved Formatting

* Wrapped comments
* Fixed spelling error for `movement` variable
* Added DOCSTRINGs

* Improved Formatting

* Corrected whitespace to improve readability.
* Added docstrings.
* Made comments fit inside an 80 column layout.
2019-07-01 16:10:18 +08:00
BruceLee569
34889fc6d8 Update quick_sort.py (#928)
Use the last element as the first pivot, for it's easy to pop, this saves one element space.
Iterating with the original list saves half the space, instead of generate a new shallow copy list by slice method.
2019-06-28 23:55:31 +08:00
CharlesRitter
6e894ba3e8 Odd-Even Transposition Sort (#769)
* -Added a single-threaded implementation of odd-even transposition sort.

This is a modified bubble sort meant to work with multiple processors.
Since this is running on a single thread, it has the same running time
as bubble sort.

* -Added a parallel implementation of Odd-Even Transposition sort

This implementation uses multiprocessing to perform the swaps
at each step of the algorithm simultaneously.
2019-06-07 23:38:43 +08:00
Anup Kumar Panwar
71be23999c refactor 2019-05-26 21:56:10 +05:30
Mehdi ALAOUI
02c0daf9e5 Adding unit tests for sorting functions, and improving readability on some sorting algorithms (#784)
* Adding variable to fade out ambiguity

* More readability on merge sorting algorithm

* Updating merge_sort_fastest description and explaining why

* Adding tests file with imports

* Standardazing filenames and function names

* Adding test cases and test functions

* Adding test loop

* Putting 'user oriented code' inside main condition for having valid imports

* Fixing condition

* Updating tests: adding cases and todo list

* Refactoring first euler problem's first solution
2019-05-25 21:41:24 +08:00
José Henrique Ivanchechen
9f982a83c8 add pigeon hole sort (#833) 2019-05-24 22:46:39 +05:30
BruceLee569
a0ab3ce098 Update quick_sort.py (#830)
Modify the list comprehensions to reduce the number of judgments, the speed has increased by more than 50%.
2019-05-24 23:54:03 +08:00
Níkolas Vargas
023f5e092d fix empty list validation and code data structures (#826)
* fix empty list validation and code data structures

* Update bucket_sort.py

https://github.com/TheAlgorithms/Python/pull/826#pullrequestreview-240357549
2019-05-22 20:09:36 +08:00
Adam
c1130490d7 fix spelling on line 44 of bucket sort (#824)
* change besd to best
2019-05-20 21:22:20 +08:00
Andy Lau
f5abc04176 Update bucket_sort.py (#821)
* Some simplification
2019-05-19 17:00:54 +08:00
Tommy.Liu
3c40fda6a3 More elegant coding for merge_sort_fastest (#804)
* More elegant coding for merge_sort_fastest

* More elegant coding for merge_sort
2019-05-14 18:17:25 +08:00
Gattlin Walker
06dbef04a0 Adding quick sort where random pivot point is chosen (#774) 2019-04-30 21:16:42 +08:00
sakuralethe
48553da785 variable in function should be lowercase (#768) 2019-04-26 17:43:51 +08:00
Ishani
96c36f8286 added wiggle_sort.py (#734)
* Wiggle_sort

* Rename Wiggle_Sort to wiggle_sort.py
2019-03-18 02:12:22 +08:00
Aruj Sharma
a0d5c9aaf0 Create BitonicSort.py (#386) 2019-02-11 17:53:49 +08:00
Inno Fang
17a6d1c1a7 Fix sorts/radix_sort (#338) 2019-02-09 07:44:23 +05:30
Mickaël Schoentgen
2d70e9f747 Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-01-08 16:59:23 +08:00
Ishmeet-Singh-Saggu
ce0a013ad7 Update bubble_sort.py (#535) 2018-10-27 13:21:44 +02:00
Harshil
f0d5bc6ece Merge branch 'improved_sorting_algo' of git://github.com/YasirChoudhary/Python 2018-10-26 17:25:36 +02:00
Alex Brown
91fccecb56 snake_case all the things 2018-10-19 17:14:25 -05:00
Yasir Choudhary
9561259285
Merge branch 'master' into improved_sorting_algo 2018-10-19 12:05:26 +05:30
ParthS007
0856a61859 Remove Multiple Unused Imports and Variable 2018-10-18 02:58:57 +05:30
Harshil
f9f5d402d3
Update bubble_sort.py
Added main method, Made it Python2 suitable, Enabled user input!
2018-10-16 20:39:22 +02:00
YasirChoudhary
98cc298e61 Optimised for loop iteration 2018-10-07 14:33:56 +05:30
YasirChoudhary
6a6349bdb0 Optimised for loop iteration 2018-10-07 14:32:48 +05:30
Prateek
356b51458d
done 2018-10-05 14:20:19 +05:30
Coregame
25c0bd3fbb
minor improvement (readability) in Insertion Sort 2018-10-04 13:36:16 +07:00
camilne
0e76ee9076 Remove duplicate counting sort (#376) 2018-10-02 15:06:24 +05:30
Harshil
38dbaef5f5
Merge pull request #384 from kelvins/comb_sort
Comb sort
2018-10-02 11:20:38 +02:00
rafa leyva ruiz
c0033f92ad Use local insertion sort (solves #334) (#370) 2018-10-02 14:16:56 +05:30
Kelvin Salton do Prado
f4a80fbfcb comb_sort: fix typo and indentation 2018-10-01 23:46:47 -03:00
Kelvin Salton do Prado
5fb6b31ea9 Add comb sort algorithm 2018-10-01 23:43:25 -03:00
PandllCom
ac30a97e99
typo: strip 2018-06-26 10:55:21 +08:00
Hossam Al-Dokkani
9489e8512d Break if the collection is sorted 2018-06-23 17:01:06 +02:00
Harshil
31f968f589
small change! 2018-05-28 23:34:21 +02:00
Hyuntae
ca7eb46756 quicksort_3_partition 2018-05-28 19:19:15 +09:00
Harshil
71fd719ab7
Update merge_sort_fastest.py 2018-05-21 10:28:37 +02:00
Harshil
7f4b240d1a
Update merge_sort_fastest.py
I have modified the code a little to make it work as expected!
2018-05-21 10:21:33 +02:00
Syed Haseeb Shah
237df47a31
Create merge_sort_fastest.py
Python implementation of merge sort algorithm.
Takes an average of 0.6 microseconds to sort a list of length 1000 items.
Best Case Scenario : O(n)
Worst Case Scenario : O(n)
2018-05-20 23:00:17 +05:00
Sichen Liu
744dd71238 Add sorts for python3 2018-03-03 21:27:05 -05:00
Harshil
1611f40c51
Merge branch 'master' into revert-22-patch-1 2018-01-20 16:27:17 +05:30
Sayan Bandyopadhyay
5d4471d35a
Update cyclesort.py
Changing for Python 3 using exception handling for robust code
2018-01-07 13:21:05 +05:30
cclauss
2ed1bad747
Merge branch 'master' into modernize-python2-code 2017-12-13 16:32:28 +01:00
Harshil
491439ae50
Merge pull request #129 from Balance-Breaker/master
Fixed heading's formatting errors
2017-11-28 16:58:04 +05:30
cclauss
e31c780d94 Modernize Python 2 code to get ready for Python 3 2017-11-25 12:41:55 +01:00
cclauss
4e06949072 Modernize Python 2 code to get ready for Python 3 2017-11-25 10:23:50 +01:00
Harshil
bb3287ac0a
Merge pull request #157 from Sayan97/patch-1
Update radix_sort.py
2017-11-01 10:49:05 +05:30
Honey Sharma
8c5fd4b597 Create cyclesort.py
implementation of cycle sort in python3
2017-10-27 21:00:08 +05:30
Harshil
ad935df161 Merge pull request #179 from Shivams334/master
Added new code
2017-10-27 11:08:38 +05:30
Sayan Bandyopadhyay
b96412c019 Merge branch 'master' into patch-1 2017-10-23 19:17:45 +05:30
Shivam sharma
fe7b86c9ff Add files via upload 2017-10-20 18:03:43 +05:30
Harshil
54eb79f53a Merge pull request #135 from KuLi/radix_sort-fix
#130 fixed radix sort for python 3
2017-10-17 18:50:05 +05:30
Harshil
4c9efeacb8 Merge pull request #123 from theycallmemac/master
added timsort.py
2017-10-15 09:25:45 +05:30
André Almeida
35d3873716 Add counting sort 2017-10-14 03:07:02 +00:00
Sayan Bandyopadhyay
aac224dc1b Update radix_sort.py
This will fix the error in the list index showing as float
2017-10-12 01:28:12 +05:30
Shivam sharma
14e6372196 Added counting sort in python 2017-10-10 21:41:01 +05:30
KyleScharnhorst
014786e340 Fix: typo in multiple files. 2017-10-07 06:47:50 -07:00
James Mc Dermott
a97ab2f4e4 Update timsort.py 2017-10-01 22:13:54 +01:00
KuLi
edcf6d54b6 #130 fixed radix sort for python 3 2017-09-29 23:47:24 +02:00
Ankit Dhankhar
1f0f4b2c92 Fixed heading's formatting errors 2017-09-29 23:15:33 +05:30
theycallmemac
1958cf25c5 added timsort.py 2017-09-28 20:54:15 +01:00
Omkar Pathak
ef01688b94 Added Bucket Sort implementation 2017-07-20 07:02:49 +05:30
Omkar Pathak
e8a36b12ce Added Bucket Sort implementation 2017-07-20 06:59:42 +05:30
Zach Wild
16b0d62f28 Add topological_sort.py 2017-06-21 19:11:31 -04:00
Mehdi ALAOUI
7ae9759220 Added some other spaces 2017-04-06 03:55:28 +01:00
Mehdi ALAOUI
8d06eb2c63 Added some space before and after operators 2017-04-06 03:44:47 +01:00
Mehdi ALAOUI
183df6889b Code more concise and more readable 2017-04-05 06:58:16 +01:00
James Mc Dermott
e823c55f62 Create radix_sort.py 2017-02-25 15:06:58 +00:00
Prateek Chanda
f42a1b8fbc Create normal_distribution_QuickSort_README.md 2017-02-05 17:52:31 +05:30
Anup Kumar Panwar
ea36ef407b Revert "Update Normal Distribution QuickSort Readme" 2017-02-04 18:15:41 +05:30
Anup Kumar Panwar
04f13daf10 Merge pull request #66 from prateekiiest/master
Update Normal Distribution QuickSort Readme
2017-02-04 18:15:16 +05:30
Prateek Chanda
d4e35fb430 Create normal_distribution_QuickSort_README.md 2017-02-04 15:02:23 +05:30
Prateek Chanda
f707513eea Rename randomquicksort.py to random_normaldistribution_quicksort.py 2017-02-04 13:59:48 +05:30
Prateek Chanda
3040022f0b Create randomquicksort.py 2017-02-04 12:20:55 +05:30
Prateek Chanda
a3ab980816 random_normaldistribution_quicksort
This is for creating an algorithm implementing QuickSort Algorithm where the pivot element is chosen randomly between first and last elements of the array and the array elements are taken from a Standard Normal Distribution.

This is different from the ordinary quicksort in the sense, that it applies more to real life problems , where elements usually follow a normal distribution. Also the pivot is randomized to make it a more generic one.
2017-02-03 22:02:05 +05:30
alvin562
839a84182c updated version 2017-01-03 00:08:42 -08:00
Prateek Chanda
d521e5ecc6 Add files via upload 2016-12-13 16:17:57 +05:30
Tommi Laivamaa
8f93472071 Added implementations of gnome sort and cocktail shaker sort 2016-12-04 17:00:20 +02:00
Akshay Sharma
9deae5d14c PEP style and tree traversals 2016-09-26 02:45:14 +05:30
phlai
119da45c52 for better bubble sort 2016-09-11 17:51:34 +08:00
yyeltsyn
a681b24f69 Update insertion_sort.py
Cleaner solution: shorter, less variables, straightforward logic.
2016-09-05 10:08:04 +03:00