nthperm

Version 1.0.0.0 (4,21 KB) von Peter Li
Directly compute Nth lexicographic permutation
380 Downloads
Aktualisiert 31. Dez 2013

Lizenz anzeigen

Given a SORTED input vector V and positive integer n, rearranges V into its Nth lexicographic permutation. V must be SORTED or the behavior will not be correct. Sorted has flexible meaning however; see internal documentation.

Compare this with the output of my NEXTPERMS submission, which generates a series of sequential lexicographic pemutations in blocks. This instead generates the Nth permutation directly by a factorial radix rebasing; see http://en.wikipedia.org/wiki/Factorial_number_system for more information.

This will be much more efficient than running through the permutations sequentially if the desired permutation is deep in a large set.

Mex C++ and pure Matlab both provided; they should hopefully behave identically.

Basically the same idea as ONEPERM submission, but that submission generates the permutations in a recursive order, similar to the behavior of Matlab's PERMS. NTHPERM generates the permutation in lexicographic order to match NEXTPERMS, which is based on the C++ STL next_permutation function.

Zitieren als

Peter Li (2024). nthperm (https://www.mathworks.com/matlabcentral/fileexchange/44887-nthperm), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2012a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und MATLAB Answers
Quellenangaben

Inspiriert von: ONEPERM

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0