I've been studying algorithms like crazy for a big interview. This particular algorithm is driving me crazy I've added comments to some lines that don't understand.
def permute(s):
out = []
if len(s) == 1:
# wouldn't setting out replace everything in out?
out = [s]
else:
for i, let in enumerate(s):
# how does it know that I only want 2 strings?
for perm in permute(s[:i] + s[i+1:]):
out += [let + perm]
return out
print permute("cat")
Is it correct to say that the time complexity of this algorithm is O(n!)?