Narayana Algorithm For Next Lexicographic Permutation
This online calculator implements Narayana algorithm to generate the next permutation in lexicographic order
This content is licensed under Creative Commons Attribution/ShareAlike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work https://planetcalc.com/8520/. Also, please do not modify any references to the original work (if any) contained in this content.
This online calculator illustrates the operation of Narayana's nonrecursive algorithm for generating permutations in lexicographic order. You enter the elements of the initial permutation, separated by commas, and the number of iterations of the algorithm (the permutation obtained in the previous iteration is the initial permutation of the next iteration). The default data  permutation 1,2,3 and number of iterations 6 generates all possible permutations of three elements (three factorial) and returns to the initial permutation.
This is illustrated by the fact that if Narayana algorithm is applied in a loop to an initial sequence of elements ordered such that , it will generate all permutations of the elements of the set in lexicographic order^{1}.
You can read the description of the algorithm below the calculator.
Narayana Algorithm
 Find such a largest for which .
 Increase . To do this, find the largest for which . Then swap and .
 Write the sequence in reverse order.
The algorithm was invented by Indian mathematician Pandit Narayana in the 14th century.

Knuth, D. E. The Art of Computer Programming. — AddisonWesley, 2005. — Vol. 4. — ISBN 0201853930 ↩
Comments