|
1 |
| -/* |
2 |
| -[Wikipedia says](https://en.wikipedia.org/wiki/Bucket_sort#:~:text=Bucket%20sort%2C%20or%20bin%20sort,applying%20the%20bucket%20sorting%20algorithm.&text=Sort%20each%20non%2Dempty%20bucket.): Bucket sort, or bin sort, is a sorting algorithm that works by distributing the |
3 |
| -elements of an array into a number of buckets. Each bucket is then sorted individually, either using |
4 |
| -a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a |
5 |
| -distribution sort, and is a cousin of radix sort in the most to least significant digit flavour. |
6 |
| -Bucket sort is a generalization of pigeonhole sort. Bucket sort can be implemented with comparisons |
7 |
| -and therefore can also be considered a comparison sort algorithm. The computational complexity estimates |
8 |
| -involve the number of buckets. |
9 |
| -
|
10 |
| -Time Complexity of Solution: |
11 |
| -Best Case O(n); Average Case O(n); Worst Case O(n) |
12 |
| -
|
13 |
| -*/ |
14 |
| - |
15 | 1 | /**
|
16 |
| - * bucketSort returns an array of numbers sorted in increasing order. |
| 2 | + * BucketSort implementation. |
| 3 | + * |
| 4 | + * Wikipedia says: Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array |
| 5 | + * into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by |
| 6 | + * recursively applying the bucket sorting algorithm. It is a distribution sort, and is a cousin of radix sort in the |
| 7 | + * most to least significant digit flavour. Bucket sort is a generalization of pigeonhole sort. Bucket sort can be |
| 8 | + * implemented with comparisons and therefore can also be considered a comparison sort algorithm. The computational |
| 9 | + * complexity estimates involve the number of buckets. |
| 10 | + * |
| 11 | + * @see https://en.wikipedia.org/wiki/Bucket_sort#:~:text=Bucket%20sort%2C%20or%20bin%20sort,applying%20the%20bucket%20sorting%20algorithm.&text=Sort%20each%20non%2Dempty%20bucket. |
| 12 | + * |
| 13 | + * Time Complexity of Solution: |
| 14 | + * Best Case O(n); Average Case O(n); Worst Case O(n) |
17 | 15 | *
|
18 | 16 | * @param {number[]} list The array of numbers to be sorted.
|
19 | 17 | * @param {number} size The size of the buckets used. If not provided, size will be 5.
|
20 | 18 | * @return {number[]} An array of numbers sorted in increasing order.
|
21 | 19 | */
|
22 |
| -function bucketSort (list, size) { |
| 20 | +export function bucketSort (list, size) { |
23 | 21 | if (undefined === size) {
|
24 | 22 | size = 5
|
25 | 23 | }
|
@@ -60,5 +58,3 @@ function bucketSort (list, size) {
|
60 | 58 | }
|
61 | 59 | return sorted
|
62 | 60 | }
|
63 |
| - |
64 |
| -export { bucketSort } |
0 commit comments