Full permutation algorithm (dictionary order method, SJT algorithm, Heap ' s algorithm)

Source: Internet
Author: User

First, the dictionary order method

1) from the right end of the sequence p, scan to the left until you find the first number that is smaller than the number on the right.

2) from the right, find all the smallest numbers in the larger number, ie.

3) Exchange with.

4) Flip the sequence on the right to get the next permutation of the dictionary order.

5) Repeat the above steps until you get the largest order in the dictionary order, that is, the left number is larger than the right.



Second, SJT algorithm

The initial state is.

1) Find the maximum movable number m (when a number points to a number smaller than it is, the number is the number of movable)

2) interchange M and m pointing to the number of

3) Change the direction of all numbers larger than M

4) Repeat the above steps until you cannot find the movable number



Third, Heap ' s algorithm

Procedure generate (N:integer, A:array of any):    if n = 1 then          output (A)    else for        i: = 1; i≤n; i + = 1 Do            generate (n-1, A)            if n was odd then                j←1            else                j←i            swap (A[j], a[n])
The above algorithm description is excerpted from Wikipedia




Full permutation algorithm (dictionary order method, SJT algorithm, Heap ' s algorithm)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.