The only way I'll keep learning more algorithms. :)
EDIT: Currently, I'm pursuing a certification so I'm pausing 1algo1week project.
Radix LSD
Radix is a sorting algorithm which sorts integers by grouping them by the individual digits. Link at the USFCA has a great visualization. This version starts from the least significant digit (LSD).
Ruby implementation:
def radix_lsd(list)
passes = (list.max == 0) ? 1 : Math.log10(list.max).to_i + 1
second_list = []
passes.times do |pass|
buckets = Array.new(10, [])
list.each do |num|
digit = num % (10 ** (pass + 1)) / (10 ** pass)
buckets[digit] += [num]
end
buckets, second_list = Array.new(10, []), buckets.flatten
end
second_list
end
p radix_lsd(Array.new(10).map{ rand(5) })
There is a lot of interesting work around analysis and complexity of this algorithm so check it out.