pub fn radix_sort(arr: &mut [i32])
Expand description
Sorts a slice using the Radix Sort algorithm.
Radix sort processes the elements digit by digit, sorting them by each digit starting from the least significant digit.
§Parameters
arr
: A mutable reference to the slice of integers to be sorted.
§Time Complexity
- Best:
O(nk)
- Worst:
O(nk)
- Average:
O(nk)
§Space Complexity
O(n + k)
(requires additional space for the buckets)
§Examples
use dsa::algorithms::sorting::radix_sort;
let mut arr = [170, 45, 75, 90, 802, 24, 2, 66];
radix_sort(&mut arr);
assert_eq!(arr, [2, 24, 45, 66, 75, 90, 170, 802]);