in reply to Searching for a Permutation Algorithm for nPr where n != r

I don't have my text book in front of me, but this can be seen as a graphing problem.

Take N items and put them in a fully connected complete graph. Everything is connected to everything. What you are asking for is all paths of length 2, in the case of nP2 I believe it's an n^3'd problem involving three for loops (update, i thought it was two, but my heart says 3).

If you don't have to store all of your text somewhere, you can probably derive the letters by their indicies (i=0 is the same as i=A, i=1 is the same as i=B).

It's not a solution, but if you take a look at some graphing algorithm chapters, it may give you some ideas.

  • Comment on Re: Searching for a Permutation Algorithm for nPr where n != r