RECPERMS (Recursive Permutations)
by Khaled Hamed
23 Nov 2006
(Updated 27 Nov 2006)
Produce permutations of the integers from 1 to n recursively one at a time.
|
Watch this File
|
| File Information |
| Description |
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. |
| MATLAB release |
MATLAB 7.3 (R2006b)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Comments and Ratings (1) |
| 21 Oct 2007 |
Domingo Moon
|
|
|
|
Contact us at files@mathworks.com