Analysis of the whole permutation algorithm

Source: Internet
Author: User

Original address: https://blog.csdn.net/summerxiachen/article/details/60579623

1. All-ranked definitions and formulas:

The number of M (m<=n) from the n number is sorted into a column in a certain order, which is called an arrangement to take m elements from n elements. By the definition of permutations, obviously the different order is a different arrangement. The number of all permutations that take m elements from n elements, called permutations. A permutation of n elements from n elements is called a full arrangement. The permutation number formula is n! and can be obtained by multiplication principle. 2. Complexity of Time:

n the number (character, object) of the entire arrangement has a total of n! species, so the total permutation algorithm at least time O (n!) O (n!) Of If you want to output the full arrangement, then the output time to O (n∗n!) O (n∗n!), because each permutation has n data. So in fact, the full array algorithm is not able to deal with large data, and in general, it does not require us to traverse the whole arrangement of a large data. 3. List the initial ideas in full alignment:

To solve an algorithm problem, I am more accustomed to starting from the basic idea, we first review how we write a set of the full array of numbers: 1,3,5,9 (for convenience, I use numbers for all permutations instead of characters).
"1,3,5,9" (first)
First, keep the first one unchanged and arrange the "3,5,9" all the same.
In the same way, we first keep the 3 unchanged and arrange the "5,9" all the way.
Keep 5 unchanged, the 9 pairs are all arranged, because 9 has only one, it arranges only one: 9.
So the arrangement is "1,3,5,9"
The next 5 can't start with 5, 5,9 exchange, get
"1,3,9,5"
At this time 5,9 of the situation are finished, can not start with 3, get

1,5,3,9
1,5,9,3
1,9,3,5
1,9,5,3

In this way, we get all the permutations at the beginning of 1, which is the process of generating our general permutation numbers. And then it starts with 3, 5, 9, and it's all arranged.

We are now making the assumption that, assuming that the first digit in a given sequence is not the same, it can be assumed that the sequences must not be the same sequence, which is an obvious problem. With this conclusion, we can get the same result that if the first bit is the same, but the second is different, then the sequence must not be the same.
Well, that's a question to look at. Right

t= "t=" x1,x1,x2,x3,x4,x5,........ xn−1,xn "x2,x3,x4,x5,........ xn−1,xn"

After all the cases in the first position (note: All the cases), for each case, the first position in the sequence TT is drawn, then the remaining sequence can be considered as a new sequence

t1= "x2,x3,x4,x5,........ xn−1,xn" t1= "x2,x3,

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.