algorithm to generate full permutation