Question: As you know from Discrete Math, a permutation is any possible ordering of the distinct items of a set S . If | S |

As you know from Discrete Math, a permutation is any possible ordering of the distinct items of a set S. If |S|= n, there are n! permutations. This means that for large sets, it is computationally infeasible to generate all possible permutations. One well-known algorithm for generating set permutations (at least for small sets) is presented below:ALGORITHM Johnson-Trotter(n)// Input: a positive integer n// Output: A list of all permutations of {1,2,, n}initialize the first permutation as 12 n with directions pointing leftwhile the last permutation has a mobile elementfind its largest mobile element kswap k and the element to which k is directedreverse the direction of all elements that are larger than kadd the new permutation to the listNote: an element is mobile if its direction points to a smaller adjacent element

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!