From 49248a059970d9096e50c5ee0ac54141a59f3de8 Mon Sep 17 00:00:00 2001 From: Carlos Abraham Date: Wed, 10 Oct 2018 11:27:15 -0400 Subject: [PATCH 1/3] add new algorithms on the tree --- docs/readme.md | 12 +++++++++--- readme.md | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 2995cc4..0f37fe0 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -55,10 +55,16 @@ print(binary_search(arr, 3)) # Tree -- Searches +- ### Searches - [Binary Search](searches/binary-search) -- Sorting - - [Merge Sort](sorting/merge-sort) +- ### Sorting + - [Bubble Sort](sorting/bubble-sort) + - [Cocktail Shaker Sort](sorting/cocktail-shaker-sort) + - [Insertion Sort](sorting/insertion-sort) + - [Merge Sort](sorting/merge-sort) + - [Pidgeonhole Sort](sorting/pidgeonhole-sort) + - [Selection Sort](sorting/selection-sort) + - [Stooge Sort](sorting/stooge-sort) # Related diff --git a/readme.md b/readme.md index 2a480f2..e43ba69 100644 --- a/readme.md +++ b/readme.md @@ -55,11 +55,16 @@ print(binary_search(arr, 3)) # Tree -- Searches +- ### Searches - [Binary Search](https://python.allalgorithms.com/searches/binary-search) -- Sorting - - [Merge Sort](https://python.allalgorithms.com/sorting/merge-sort) - +- ### Sorting + - [Bubble Sort](https://python.allalgorithms.com/sorting/bubble-sort) + - [Cocktail Shaker Sort](https://python.allalgorithms.com/sorting/cocktail-shaker-sort) + - [Insertion Sort](https://python.allalgorithms.com/sorting/insertion-sort) + - [Merge Sort](https://python.allalgorithms.com/sorting/merge-sort) + - [Pidgeonhole Sort](https://python.allalgorithms.com/sorting/pidgeonhole-sort) + - [Selection Sort](https://python.allalgorithms.com/sorting/selection-sort) + - [Stooge Sort](https://python.allalgorithms.com/sorting/stooge-sort) # Related From 7cf18d379bcea5cc98c616dc46039753377e6591 Mon Sep 17 00:00:00 2001 From: Carlos Abraham Date: Wed, 10 Oct 2018 11:33:48 -0400 Subject: [PATCH 2/3] type from 'pidgeonhole' to 'pigeonhole' sort --- .../sorting/{pidgeonhole_sort.py => pigeonhole_sort.py} | 5 ++--- docs/readme.md | 2 +- docs/sorting/{pidgeonhole-sort.md => pigeonhole-sort.md} | 8 ++++---- readme.md | 2 +- tests/test_sorting.py | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) rename allalgorithms/sorting/{pidgeonhole_sort.py => pigeonhole_sort.py} (88%) rename docs/sorting/{pidgeonhole-sort.md => pigeonhole-sort.md} (84%) diff --git a/allalgorithms/sorting/pidgeonhole_sort.py b/allalgorithms/sorting/pigeonhole_sort.py similarity index 88% rename from allalgorithms/sorting/pidgeonhole_sort.py rename to allalgorithms/sorting/pigeonhole_sort.py index aa0e709..c7ce64f 100644 --- a/allalgorithms/sorting/pidgeonhole_sort.py +++ b/allalgorithms/sorting/pigeonhole_sort.py @@ -1,14 +1,13 @@ # -*- coding: UTF-8 -*- # -# Pidgeonhole Sort Algorithm +# Pigeonhole Sort Algorithm # The All â–²lgorithms library for python # # Contributed by: Martmists # Github: @martmists # - -def pidgeonhole_sort(data): +def pigeonhole_sort(data): minimum = min(data) size = max(data) - minimum + 1 holes = [0] * size diff --git a/docs/readme.md b/docs/readme.md index 0f37fe0..867bc1e 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -62,7 +62,7 @@ print(binary_search(arr, 3)) - [Cocktail Shaker Sort](sorting/cocktail-shaker-sort) - [Insertion Sort](sorting/insertion-sort) - [Merge Sort](sorting/merge-sort) - - [Pidgeonhole Sort](sorting/pidgeonhole-sort) + - [Pigeonhole Sort](sorting/pigeonhole-sort) - [Selection Sort](sorting/selection-sort) - [Stooge Sort](sorting/stooge-sort) diff --git a/docs/sorting/pidgeonhole-sort.md b/docs/sorting/pigeonhole-sort.md similarity index 84% rename from docs/sorting/pidgeonhole-sort.md rename to docs/sorting/pigeonhole-sort.md index 8fa568e..d74631b 100644 --- a/docs/sorting/pidgeonhole-sort.md +++ b/docs/sorting/pigeonhole-sort.md @@ -1,4 +1,4 @@ -# Pidgeonhole Sort +# Pigeonhole Sort Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the length of the range of possible key values (N) are approximately the same. It requires O(n + N) time. It is similar to counting sort, but differs in that it "moves items twice: once to the bucket array and again to the final destination [whereas] counting sort builds an auxiliary array then uses the array to compute each item's final destination and move the item there." @@ -11,17 +11,17 @@ pip install allalgorithms ## Usage ```py -from allalgorithms.sorting import pidgeonhole_sort +from allalgorithms.sorting import pigeonhole_sort arr = [77, 2, 10, -2, 1, 7] -print(pidgeonhole_sort(arr)) +print(pigeonhole_sort(arr)) # -> [-2, 1, 2, 7, 10, 77] ``` ## API -### pidgeonhole_sort(array) +### pigeonhole_sort(array) > Returns a sorted array diff --git a/readme.md b/readme.md index e43ba69..cfbee77 100644 --- a/readme.md +++ b/readme.md @@ -62,7 +62,7 @@ print(binary_search(arr, 3)) - [Cocktail Shaker Sort](https://python.allalgorithms.com/sorting/cocktail-shaker-sort) - [Insertion Sort](https://python.allalgorithms.com/sorting/insertion-sort) - [Merge Sort](https://python.allalgorithms.com/sorting/merge-sort) - - [Pidgeonhole Sort](https://python.allalgorithms.com/sorting/pidgeonhole-sort) + - [Pigeonhole Sort](https://python.allalgorithms.com/sorting/pigeonhole-sort) - [Selection Sort](https://python.allalgorithms.com/sorting/selection-sort) - [Stooge Sort](https://python.allalgorithms.com/sorting/stooge-sort) diff --git a/tests/test_sorting.py b/tests/test_sorting.py index 7fe083c..6c1913a 100644 --- a/tests/test_sorting.py +++ b/tests/test_sorting.py @@ -5,7 +5,7 @@ insertion_sort, merge_sort, selection_sort, - pidgeonhole_sort, + pigeonhole_sort, stooge_sort, cocktail_shaker_sort ) @@ -24,7 +24,7 @@ def test_insertion_sort(self): def test_selection_sort(self): self.assertEqual([-44, 1, 2, 3, 7, 19], selection_sort([7, 3, 2, 19, -44, 1])) - def test_pidgeonhole_sort(self): + def test_pigeonhole_sort(self): self.assertEqual([-44, 1, 2, 3, 7, 19], pidgeonhole_sort([7, 3, 2, 19, -44, 1])) def test_stooge_sort(self): From d8ddec42a5d328e92df8445333207a5ec7fe7f9a Mon Sep 17 00:00:00 2001 From: Carlos Abraham Date: Wed, 10 Oct 2018 11:42:48 -0400 Subject: [PATCH 3/3] fix function typo on TestSorting --- tests/test_sorting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sorting.py b/tests/test_sorting.py index 6c1913a..0f84a4f 100644 --- a/tests/test_sorting.py +++ b/tests/test_sorting.py @@ -25,7 +25,7 @@ def test_selection_sort(self): self.assertEqual([-44, 1, 2, 3, 7, 19], selection_sort([7, 3, 2, 19, -44, 1])) def test_pigeonhole_sort(self): - self.assertEqual([-44, 1, 2, 3, 7, 19], pidgeonhole_sort([7, 3, 2, 19, -44, 1])) + self.assertEqual([-44, 1, 2, 3, 7, 19], pigeonhole_sort([7, 3, 2, 19, -44, 1])) def test_stooge_sort(self): self.assertEqual([-44, 1, 2, 3, 7, 19], stooge_sort([7, 3, 2, 19, -44, 1]))