The only way I'll keep learning more algorithms. :)
EDIT: Currently, I'm pursuing a certification so I'm pausing 1algo1week project.
Radix MSD
Radix is a sorting algorithm which sorts integers by grouping them by the individual digits. This version starts from the most significant digit (MSD).
Ruby implementation:
def radix_msd(array, base=10)
rounds = (Math.log(array.minmax.map(&:abs).max) / Math.log(base)).ceil
rounds.times do |i|
result = Array.new(2 * base){[]}
array.each do |n|
digit = (n / (base ** i)) % base
digit += base if n > 0
result[digit] << n
end
array = result.flatten
end
array
end
p radix_msd(Array.new(10).map{ rand(5) })
There is a lot of interesting work around analysis and complexity of this algorithm so check it out.