A deliberately inefficient sorting algorithm that demonstrates the concept of space-time trade-offs taken to an impractical extreme.
It maps values into a sparse memory array using sum residuals, compacts the non-null elements, and flips the resulting structure to achieve ascending order.
Most sorting algorithms optimize for speed and memory footprint. SlowDuckSort was designed as an experimental counter-example: what happens if an algorithm uses memory address translation based on array totals instead of traditional comparison loops?
The result is technically functional, visually distinct, but intentionally slow and memory-heavy.
- Total Sum Calculation: The sum of all elements in the array is calculated.
- Sparse Array Mapping: For each element
x, its placement index is calculated as:residual = total_sum - xThe element is then placed atRAM[residual]. Unused slots remain empty (None). - Compaction: The algorithm scans the sparse array, ignores all
Nonevalues, and collects the placed elements side-by-side into a continuous array. - Final Reversal: Since larger original values produce smaller residuals, the compacted array is naturally in descending order. A final flip reverses the array into ascending order.

