@@ -36,6 +36,7 @@ $ pip install py-algorithms
36
36
- Binary Search
37
37
38
38
^ Sorting
39
+ - Shell Sort (Shell method)
39
40
- Heap Sort (Fibonacci heap)
40
41
- Merge Sort
41
42
- Bubble Sort
@@ -120,6 +121,7 @@ sorting_algorithm(xs)
120
121
121
122
# => [-1, 0, 4, 5, 6, 7, 8, 9, 12]
122
123
```
124
+
123
125
#### * Heap Sort (https://en.wikipedia.org/wiki/Heapsort)
124
126
125
127
In computer science, heapsort is a comparison-based sorting algorithm.
@@ -143,6 +145,33 @@ sorting_algorithm(xs)
143
145
144
146
# => [-1, 0, 4, 5, 6, 7, 8, 9, 12]
145
147
```
148
+
149
+ #### * Shell Sort (https://en.wikipedia.org/wiki/Shellsort)
150
+
151
+ Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort.
152
+ It can be seen as either a generalization of sorting by exchange (bubble sort) or
153
+ sorting by insertion (insertion sort). The method starts by sorting pairs of elements far apart
154
+ from each other, then progressively reducing the gap between elements to be compared.
155
+ Starting with far apart elements, it can move some out-of-place elements into position faster
156
+ than a simple nearest neighbor exchange. Donald Shell published the first version of this sort in 1959
157
+ The running time of Shellsort is heavily dependent on the gap sequence it uses. For many practical variants,
158
+ determining their time complexity remains an open problem.
159
+
160
+ Worst case: О(n^2)
161
+ Best case: О(n log n)
162
+ Average: ~
163
+ Worst case space: O(n)
164
+
165
+ ``` python
166
+ from py_algorithms.sort import new_shell_sort
167
+
168
+ xs = [0 , 6 , 7 , 8 , 9 , 4 , 5 , 12 , - 1 ]
169
+ sorting_algorithm = new_shell_sort()
170
+ sorting_algorithm(xs)
171
+
172
+ # => [-1, 0, 4, 5, 6, 7, 8, 9, 12]
173
+ ```
174
+
146
175
---
147
176
148
177
### Search Algorithms
0 commit comments