Lexicographic Ordering
Overview
A lexicographic ordering of English words is the ordering of the words as found within a dictionary.
Iteration
We can find the next lexicographic ordering of an array via a procedure of "pivot", "swap", and "reverse".
[ a₁ a₂ ... aᵢ | aᵢ₊₁ aᵢ₊₂ ... aₙ ]
Here the RHS side is the longest increasing sequence we could find, from right to left. That is,
[ a₁ a₂ ... aⱼ | aᵢ₊₁ aᵢ₊₂ ... aᵢ ... aₙ ]
Notice the RHS remains in sorted order. Since
[ a₁ a₂ ... aⱼ | aₙ ... aᵢ ... aᵢ₊₂ aᵢ₊₁ ]
Eventually the swapped