kb
That's a picture of me in Central Park, New York
Krishna Bharadwaj
Geek, Programmer, FOSS Enthusiast, CS grad student @ USC. Loves Python / Django
I can be reached on
krishna [at] krishnabharadwaj [dot] info
Here are some of my other online profiles
Powered by Python and Django

Johnson Trotter Algorithm to generate Permutations! 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


blog comments powered by Disqus