Incorrect sorting Formula

Source: Internet
Author: User

 

1. Recursive Method derivation of the error sorting Formula

When N numbered elements are placed in N numbered positions, the number of methods that do not correspond to each element number is represented by M (N), then M (n-1) it indicates that n-1 number elements are placed at N-1 numbers, and the number of methods does not correspond to each other, and so on.

Step 1: place the nth element in a single position, such as position K. There are n-1 methods in total;

Step 2: place the element number K. In this case, place it in the position N. For N-1 1 elements, since the K element to the position N, the remaining N-2 element has m (n-2) method; (2) the K element does not put it to the position N, then, for the n-1 elements, there are m (n-1) methods;

In summary

  M (n) = (n-1) [M (n-2) + M (n-1)]

In particular, M (1) = 0, M (2) = 1

The following formula is derived from this recursive relationship:

For convenience, Set M (K) = k! N (k), (k = 1, 2 ,..., N)

N (1) = 0, N (2) = 1/2

N> = 3, n! N (n) = (n-1) (n-1 )! N (n-1) + (n-1 )! N (n-2)

That is, NN (n) = (n-1) n (n-1) + N (n-2)

So there is n (n)-N (n-1) =-[n (n-1)-N (n-2)]/n = (-1/n) [-1/(n-1)] [-1/(n-2)]… (-1/3) [N (2)-N (1)] = (-1) ^ n/n!

Therefore

N (n-1)-N (n-2) = (-1) ^ (n-1)/(n-1 )!

N (2)-N (1) = (-1) ^ 2/2!

Add to get

N (n) = (-1) ^ 2/2! +... + (-1) ^ (n-1)/(n-1 )! + (-1) ^ n/n!

Therefore

M (n) = n! [(-1) ^ 2/2! +... + (-1) ^ (n-1)/(n-1 )! + (-1) ^ n/n!]

You can get

The error row formula is m (n) = n! (1/2! -1/3! + ..... + (-1) ^ n/n !)

 

2. Refresh Principle

Positive integers 1, 2, 3 ,...... And n are arranged in full order with n! (N-1 )!, When K is 1, 2, 3 ,...... , N, there are N * (n-1 )! Sorting, because it is a wrong arrangement, these arrangements should be excluded, but at this time there are two good rows of the Arrangement of multiple rows in addition to one, should be done; in addition, make up one more order with three good rows at the same time, and exclude them ;......; Continue this process and get the number of wrong columns

M (n) = n! -N! /1! + N! /2! -N! /3! +... + (-1) ^ N * n! /N! = Sigma (k = 2 ~ N) (-1) ^ K * n! /K!

That is, M (n) = n! [1/0! -1/1! + 1/2! -1/3! + 1/4! +... + (-1) ^ n/n!]

Note: Sigma indicates the concatenation of symbols (k = 2 ~ N) is the connection range.

3. Simplified Formula

In addition, the formula for troubleshooting in the book is DN = n! (1/0! -1/1! + 1/2! -1/3! -... + (-1) ^ n/n !), This formula is inconvenient to calculate n when it is very large. later it was found that it can be reduced to a beautiful formula using series knowledge = [n! /E + 0.5], [x] is the integer function, that is, X is the rounded down.

The formula is relatively simple. Observe the formula in the general book, you can find that the E-1 before the same, and then compare/dN-n! E-1/<1/(n + 1) <0.5, so we get this simple and elegant formula (this is for reference only)

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.