American flag sort works by successively dividing a list of objects into buckets based on the first digit of their base-N representation (the base used is referred to as the "radix"). When "N" is 3, each object can be swapped into the correct bucket by using the Dutch national flag algorithm. When "N" is larger, however, objects cannot be immediately swapped into place, because it is unknown where each bucket should begin and end. American flag sort gets around this problem by making two passes through the array. The first pass counts the number of objects that belong in each of the "N" buckets. The beginning of each bucket is then computed as the sum of sizes of the preceding buckets. The second pass puts each object into the correct bucket.