Optimized bucket (radix) sort with counting sort