I'm having trouble drawing a recursion tree for the following permutation code:
def permut(array):
if len(array) == 1:
return [array]
res = []
for permutation in permut(array[1:]):
print permutation, array
for i in range(len(array)):
res.append(permutation[:i] + array[0:1] + permutation[i:])
return res
Let's say my array is 'mick' then I get the following print outs for permutation and array:
k and ck
ck and ick
kc and ick
ick and mick
I understand it until 'k' and 'ck' (as when array = 'ck' len(arraw[1:]) == 1) but how do we ever get 'ick' as an array in the recursion? Could you visualize this anyhow? Thanks a lot for any tips!