3

I came across this sorting algorithm called american sort. I read it being a variant of radix sort. Can someone elaborate me regarding this sorting algorithm and also the time and space complexity related to it.

gsamaras
  • 71,951
  • 46
  • 188
  • 305

1 Answers1

2

You are referring to the American flag sort, an efficient, in-place variant of radix sort that distributes items into hundreds of buckets. It is a Distribution Sort: where items are distributed from the input to multiple intermediate structures (buckets in this case), which are then gathered and placed on the output.


Radix sort: Time: O(nk), Space: O(n+k), n is the number of keys, k is the maximum number of digits a number (value) can have.

American flag sort: Time: O(n*k/d), Space: O(k), n is the number of digits and k is the average bucket size.


Read more in american flag sort optimization.

Read Engineering Radix Sort (1993), where in the paper experimental comparison is presented between the two algorithms.

A Java implementation of American Flag Sort.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • `Space: In-place` doesn't account for `counts` and `offsets` arrays, they are presumably `O(k)`, if `k` is radix or the number of buckets. – vgru Jun 18 '18 at 09:05