Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I hope someone can help me answer the following question. Thanks!

Here is a pseudo code of Permute-By-Sorting algorithm:

Permute-By-Sorting (A)

    n = A.length

    let P[1..n] be a new array

    for i = 1 to n

    P[i] = Random (1,n^3)

         sort A, using P as sort keys

In the above algorithm, the array P represents the priorities of the elements in array A. Line 4 chooses a random number between 1 and n^3.

The question is what is the probability that all priorities in P are unique? and how do I get the probability?

share|cite|improve this question
    
By "all priorities are unique" I think you mean "all priorities are different." "Unique" does not mean "different." – bof May 15 at 23:31

You generate $n$ numbers in a range of $n^3$ numbers. There are

$$ \frac{n^3!}{(n^3-n)!} $$

favourable outcomes and a total of

$$ \left(n^3\right)^n $$

outcomes, so the probability is

$$ \frac{n^3!}{(n^3-n)!\left(n^3\right)^n}\;. $$

share|cite|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.