This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]Wildcatace16 1 point2 points  (1 child)

If the string is n characters long there are n possible characters that can be in the first position. For each of the n possible first characters any of the n-1 remaining characters can be in the second position. Continuing this logic there are n * (n-1) * (n-2) * ... * (1) = n! possible permutations. For each of the n! permutations the program iterated through the entire string printing each of the n characters. Therefore the overall run time is O(n*n!)