[Prev][Next][Index][Thread]

Re: Quick permutations! ith permutation?



dauclair@hotmail.com wrote:


> Okay, so is there an efficient way to compute only the ith permutation?
> What I mean here is that I don't want to pay for the entire computation
> up front -- I'm willing to pay for computation of the ith element as I
> go.  Also, I don't want the entire permutation list in memory, just the
> ith element (or, say, less than 100 elements, at any rate).  The stream
> protocol would be lovely but is not necessary.  Constant retrieval over
> 0 <= i < n is important.

Look for the Fisher-Yates algorithm.

Jochen



References: