|
1 | | -import random |
| 1 | +from random import randrange |
2 | 2 |
|
3 | 3 |
|
4 | 4 | def quick_sort_3partition(sorting: list, left: int, right: int) -> None: |
5 | 5 | """ " |
6 | | - Python implementation of quick sort algorithm with 3-way partition. |
7 | | - The idea of 3-way quick sort is based on "Dutch National Flag algorithm". |
| 6 | + Python implementation of the quicksort algorithm with 3-way partition. |
| 7 | + The idea of 3-way quicksort is based on "Dutch National Flag algorithm". |
8 | 8 |
|
9 | 9 | :param sorting: sort list |
10 | 10 | :param left: left endpoint of sorting |
@@ -46,7 +46,7 @@ def quick_sort_3partition(sorting: list, left: int, right: int) -> None: |
46 | 46 |
|
47 | 47 | def quick_sort_lomuto_partition(sorting: list, left: int, right: int) -> None: |
48 | 48 | """ |
49 | | - A pure Python implementation of quick sort algorithm(in-place) |
| 49 | + A pure Python implementation of the quicksort algorithm(in-place) |
50 | 50 | with Lomuto partition scheme: |
51 | 51 | https://en.wikipedia.org/wiki/Quicksort#Lomuto_partition_scheme |
52 | 52 |
|
@@ -133,7 +133,7 @@ def hoare_partition_by_value( |
133 | 133 | | | |
134 | 134 | left right |
135 | 135 |
|
136 | | - Where the middle values are [u]nknown, since they are not yet traversed. |
| 136 | + Where the middle values are unknown (u), since they are not yet traversed. |
137 | 137 | `left-1` points to the end of the left subarray. |
138 | 138 | `right+1` points to the start of the right subarray. |
139 | 139 | """ |
@@ -218,8 +218,7 @@ def quicksort_hoare(array: list, start: int = 0, end: int | None = None): |
218 | 218 | if end + 1 - start <= 1: |
219 | 219 | return |
220 | 220 |
|
221 | | - pivot_index = random.randrange(start, end) |
222 | | - pivot_index_final = hoare_partition_by_pivot(array, pivot_index, start, end) |
| 221 | + pivot_index_final = hoare_partition_by_pivot(array, randrange(start, end), start, end) |
223 | 222 | quicksort_hoare(array, start, pivot_index_final - 1) |
224 | 223 | quicksort_hoare(array, pivot_index_final + 1, end) |
225 | 224 |
|
|
0 commit comments