You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/sorting/README.md
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,21 @@
1
+
### [Bitonic Sort](./bitonic_sort.rs)
2
+
3
+
Bitonic Sort is an efficient sorting algorithm based on the bitonic sequence concept and is often used in parallel processing due to its regular and repetitive structure. It works by first sorting sub-arrays in different directions and then combining them in a special merging process, ensuring a fully sorted array. This algorithm is particularly efficient when dealing with data sets whose size is a power of two.
4
+
5
+
* Parallel Processing: Bitonic sort is highly parallelizable, making it suitable for multi-threading and distributed systems, a strength that Rust can capitalize on with its robust concurrency features.
6
+
* Recursive Strategy: The algorithm uses recursive division of the array, which is elegantly handled in Rust with its strong support for recursion and memory safety.
7
+
* Efficiency: For medium-sized arrays, especially in parallel computing environments, bitonic sort can be very efficient, leveraging Rust's performance capabilities.
8
+
9
+
__Properties__
10
+
* Special Case Input: Bitonic sort is most efficient when the input size is a power of two.
11
+
* Time Complexity: In the worst-case scenario, the time complexity of bitonic sort is O(n log² n).
12
+
* Not-in-place Sorting: While it doesn't sort in place, it requires less extra space compared to other non-in-place sorting algorithms.
From [Wikipedia][bogosort-wiki]: In computer science, bogosort (also known as permutation sort, stupid sort, slowsort or bozosort) is a sorting algorithm based on the generate and test paradigm. The function successively generates permutations of its input until it finds one that is sorted. It is not considered useful for sorting, but may be used for educational purposes, to contrast it with more efficient algorithms.
@@ -6,6 +24,18 @@ Two versions of this algorithm exist: a deterministic version that enumerates al
From [leonardini.dev][bogo-bogo-doc]: BogoBogo Sort is a humorously inefficient sorting
29
+
algorithm inspired by the original Bogosort. It adds a layer of complexity by recursively
30
+
sorting the first n-1 elements before placing the nth element. This process is repeated until
31
+
the array is sorted. The algorithm's performance is exceptionally poor, making it impractical
32
+
for sorting but a useful tool for educational purposes, especially in understanding
33
+
algorithm efficiency and recursive functions.
34
+
__Properties__
35
+
* Worst case performance (unbounded, extremely poor)
36
+
* Best case performance O(n!)
37
+
* Average case performance (unpredictable and impractical)
38
+
9
39
### [Bucket_Sort](./bucket_sort.rs)
10
40
11
41
From [Wikipedia][bucketsort-wiki]: Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort that allows multiple keys per bucket, and is a cousin of radix sort in the most-to-least significant digit flavor. Bucket sort can be implemented with comparisons and therefore can also be considered a comparison sort algorithm. The computational complexity depends on the algorithm used to sort each bucket, the number of buckets to use, and whether the input is uniformly distributed.
Strand Sort is a sorting algorithm that works by repeatedly pulling sorted sublists out of the list to be sorted and merging them with the already sorted part. It is particularly effective for sorting lists where there are large numbers of ordered elements. The algorithm is intuitive and simple, iterating through the list, picking up elements in order, and merging these 'strands' into a final sorted list.
274
+
275
+
* Simplicity: The algorithm is straightforward and easy to implement, making it a good choice for introductory sorting algorithm education.
276
+
* Adaptive: Strand sort performs well on lists that are already partially sorted, as it can quickly identify and extract these ordered sublists.
277
+
* In-place Sorting: The nature of the algorithm allows it to be implemented in an in-place fashion, although this is not always the case.
278
+
279
+

280
+
281
+
__Properties__
282
+
* Not-in-place Sorting: Typically, strand sort requires additional space for the strands, though in-place variants exist.
283
+
* Time Complexity: The average and worst-case time complexity of strand sort can vary greatly depending on the input but typically is O(n²).
284
+
* Stability: The algorithm is stable, maintaining the relative order of equal elements.
Pigeonhole Sort is a sorting algorithm that is efficient for sorting data with a known, limited range of key values. It works by creating an array of 'holes' (each representing a position in the range of the data) and then sorting the data by 'placing' each item into its corresponding hole. The algorithm then collects the items from each hole in order, resulting in a sorted array.
294
+
295
+
### Rust Implementation
296
+
The Rust implementation of Pigeonhole Sort involves the following steps:
297
+
298
+
* Initialization: First, it checks if the input array is empty. If so, it returns immediately as there's nothing to sort.
299
+
300
+
* Finding the Range: The implementation identifies the minimum and maximum values in the array. The range is the difference between these values plus one.
301
+
302
+
* Creating Holes: A vector of vectors (`Vec<Vec<i32>>`) is created to represent the holes. The size of this outer vector is equal to the range of the input data.
303
+
304
+
* Filling the Holes: The algorithm iterates over each element in the array, placing it into the corresponding hole based on its value.
305
+
306
+
* Reconstructing the Array: Finally, it iterates over the holes in order, placing each element back into the original array, now sorted.
307
+
308
+
### [Tree Sort](./tree_sort.rs)
309
+
310
+
Tree Sort is a sorting algorithm that builds a binary search tree from the elements of the array to be sorted and then performs an in-order traversal to generate a sorted array. The essence of tree sort lies in leveraging the properties of a binary search tree, where elements are inserted in such a way that for any given node, all elements in the left subtree are less than the node and all elements in the right subtree are greater.
311
+
312
+
* Safety: Rust’s adherence to memory safety is a significant asset in the implementation of tree sort. The algorithm makes use of Rust's ownership and borrowing rules to manage the tree structure without the risk of memory leaks or dangling pointers.
313
+
* Tree Construction: Rust’s powerful data handling capabilities facilitate the efficient construction and manipulation of the binary search tree, a crucial aspect of tree sort.
314
+
* Performance: While not the most efficient in all cases, tree sort in Rust can be quite performant especially for datasets that are not large, thanks to Rust's optimization capabilities.
315
+
316
+

317
+
318
+
__Properties__
319
+
* Not-in-place sorting: Tree sort requires additional memory for the binary search tree, hence it's not an in-place sorting algorithm.
320
+
* Time complexity: The average case time complexity of tree sort is O(n log n), but it can degrade to O(n²) in the worst case when the tree becomes unbalanced.
0 commit comments