## Invitation to Computer Science 8th Edition

We see that all possible lists are generated anyway, in the first loop, so we have the best possible case when the first list permutation generated is sorted. Thus, this gives 1 work unit for the second loop, giving us $$n! +1$$ work units in the best case. Similarly, in the worst case, the last list is sorted, giving us: $$n!+n! =2n!$$ work units.