Builds the final sorted array one item at a time by repeatedly inserting elements into a sorted prefix.