The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

Algorithms

Miscellaneous

Problem :-
Print all possible permutation of array elements.
Consider the array { 3, 2, 5 }.
Possible permutations : { 3, 2, 5 } | { 3, 5, 2 } | { 2, 3, 5 } | { 2, 5, 3 } | { 5, 2, 3 } | { 5, 3, 2 }

Solution :-
An array of length n has n ! permutations.
The implementation show below uses a recursive approach with swapping of array elements to obtain possible permutations and then swapping of elements in the permuted arrays to obtain further permutations.
We iterate over the array elements and at each iteration level, we do the swap and permute step described above. After the jth iteration, j elements in the obtained permuted arrays are fixed and we move to the next iteration.