Generating the ith permutation of N elements

Yannick Letourneau <[email protected]> Tue, 1 Jun 2010 12:57:24 -0400
Newsgroups gmane.games.devel.algorithms
Message-ID <9E4A58AAF133E74A9114B0FA0F2FCC6B8256ECBB@MDC-MAIL-CMS01.ubisoft.org>
I'm looking for a way to generate the ith permutation of N elements, at approximately O(N) cost.

All algorithms I've seen need the (i-1)th permutation in order to derive the ith permutation from it (e.g. they work incrementally).

I would just like to give it a number in the range

0 <= i < N!

and it would spit out the ith permutation, without requiring to compute the ones that come before it (which would be O(N!) ).

Is that possible ?

Any pointers appreciated.

Yannick

------------------------------------------------------------------------------

_______________________________________________
GDAlgorithms-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list