Original Post
Suppose you have a programming problem where you need to ''try every possibility''. This is often reduced to trying all permutations of something.
Permutations is a simple concept, but I cant think of an algorithm for it.
For example, suppose you have these numbers in an array: 1 2 3 4
What would be an alg to produce all permutations? For eg:
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1