1

Can someone please explain the logic behind the mathematical equation, that for finding the Nth Lexicographic rank of a string the Leading Entry is $a_q$ if $k=q\cdot (n!)+r.$ The link to the problem is Finding the n-th lexicographic permutation of a string

Art
  • 111

1 Answers1

1

The introductory post actually describes the solution pretty well. But in another way, the idea is as follows:

1) Suppose there are $n+1$ entries in the string. To get the value for the first element, calculate the largest number $q$ of complete cycles through all of the permutations of remaining entries in such way that $q(n!) \leq N$. Then the $q^{th}$ element of the string is the first element in your answer, and so it follows that the leading entry is $a_q$ where $N = q(n!) + r$

2) For the second element, let $k$ be equal to $N - q(n!) = r$, and play the same game as (1) with a string having only $n$ entries where you wish to find the $k^{th}$ permutation. It should be obvious that replacing $N$ with $k$ in (1) you get the desired result.

3) once $n$ is 0 you're done.

HexedAgain
  • 121
  • 4
  • Thanks for replying...I understand the solution...but I want to know why we are doing this..as why highest values of q and why r cannot be 0... – Art Jan 21 '15 at 18:23