Founder & CTO @SMERGERS & @wealthrox
Past - Dev Infra @Google · RF @NI · CS @USC

Currently
Founder & CTO @SMERGERS & @wealthrox
Previously
Dev Infra Intern @Google NYC RF @NI-WCDMA
Computer Science @USC
Contact
hey [at] krishnabharadwaj.info
29-May-2008

Johnson trotter algorithm gives a non recursive approach to generate permutations. The algorithm goes something like this..

while there exists a mobile integer k do
-->find the largest mobile integer k;
-->swap k and the adjacent integer its arrow points to;
-->reverse the direction of all integers that are larger than k

I'm using a character flag to maintain the direction of the mobile integers.. the code is simple, suggestions to make it more simple are always welcome 😊