RECPERMS (Recursive Permutations)

Produce permutations of the integers from 1 to n recursively one at a time.

You are now following this Submission

RECPERMS(n,p), where n is a positive integer, and p is a valid permutation of the integers from 1 to n, returns a vector with n elements containing the next permutation of the integers from 1 to n.
If RECPERMS(n,p) is called n!-1 times recursively (i.e feeding the output vector into the function for the next step) starting with p = 1:n, then
the successive outputs span the same output from perms(1:n). The order of the permutations is, however, different from that of perms(1:n), which
uses a different algorithm.
If the input p is 1:n, the used algorithm results in the last permutation being n:-1:1. Starting with p=1:n is, however, optional. The function is
designed to wrap to the first permutation (1:n) when the last permutation (n:-1:1) is reached. This way, if any (valid) starting permutation p is
used, then recursively calling the function n!-1 times spans all possible permutations as expected.

Cite As

Khaled Hamed (2026). RECPERMS (Recursive Permutations) (https://in.mathworks.com/matlabcentral/fileexchange/13101-recperms-recursive-permutations), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Design, Analysis, Benchmarking, and Verification in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0