Is there any algorithm to generate all permutations of the integers 1 to n [ Hint: The set of permutations of the integers 1 to n can be obtained from the set of permutations of the integers 1 to n1 by inserting n in each possible positions of each permutation ]
closed as off topic by Sergei Ivanov, Victor Protsak, Loop Space, Charles Matthews, José FigueroaO'Farrill Sep 6 '10 at 11:09Questions on MathOverflow are expected to relate to research level mathematics within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question. 


Knuth's The Art of Computer Programming, Volume 4, Fascicle 2: Generating all Tuples and Permutations gives efficient (nonrecursive) solutions to this and many other combinatorial enumeration problems. Section 7.2.1.2 contains 36 pages of material devoted to precisely the question you ask. 


Hint: If you understand recursion, you just answered your own question. You may also want to look at the C++ implementation of next_permutation in the STL. I was going to explain it, but http://wordaligned.org/articles/nextpermutation does a fantastic job. 

