R
R copied to clipboard
Add Postman Sort (LSD Radix Sort) in R
This implementation provides decimal LSD (Least Significant Digit) Radix Sort in R.
It sorts non-negative integers by repeatedly applying a stable counting sort to each digit, from the least significant to the most significant.
Overview
- Algorithm Type: Non-comparative, stable, digit-based sorting
- Target Data: Non-negative integer vectors
- Execution: Iteratively sorts by each digit place (1s, 10s, 100s, ...) using counting sort
- Notes: Mirrors typical Java implementations; uses base-10 digit processing
Features
- Stable sorting per digit ensures the relative order of equal elements is preserved
- Efficient for integers with limited digit width
- Easy to understand and implement using counting sort
- Handles large numbers by increasing the exponent (
exp) iteratively
Complexity
- Time Complexity (TC): O(d × (n + k))
n= number of elements,d= number of digits in the maximum element,k= radix/base (10 here)
- Space Complexity (SC): O(n + k)
- Temporary array for output + counting array per digit