kb

 

Krishna Bharadwaj

Geek, programmer, foss enthusiast, loves Python, Ex-Microsoft Student Partner, Ex-National Instruments.
You can Subscribe to my blog, Follow me on twitter

Permutations!

Apart from Johnson trotter, Permutations can be generated in many ways. The two methods i'll be discussing here are :

1. Recursive Method
2. Minimal Change Method or Bottom up approach.

1. Recursive Method

In this method, we take out a character at position 'I' and permute the rest of the string recursively. It goes something like this.. Lets say
"abc" is the string.

a + permute("bc") = abc & acb
b + permute("ac") = bac & bca
c + permute("ab") = cab & cba

There by generating all the permutations.

2. Minimal Change Method or Bottom up approach.
In this method, we start from a single character, append a new character and rotate the newly appended character covering all positions in the string. Like this..

a
ab, ba
abc,acb,cab,bac,bca,cba

←Spell Check and Word Suggestions!         Shaastra-2008 →

blog comments powered by Disqus
pony powered