-- Practice Midterm Mar 14 2022
William Wang, Abhishek Reddy, Pradeep Narayana
To prove that any n-permutation is equally likely to be generated by the Knuth shuffle, we first prove the lemma that prior to each i <= n, the subarray A[1, i - 1] contains each possible (i - 1)-permutation with probability (n - 1 + 1)!/n!. We do this by induction on i.
In the base case where i = 1, A[1, 0] is the empty array containing the 0-permutation with probability (n-1+1)!/n! = n!/n! = 1, which is true since there is exactly 1 0-permutation.
In the induction step, we assume that at i = k, the subarray A[1, k - 1] contains each possible (k - 1)-permutation with probability (n - k - 1)!/n!. A particular k-permutation is composed of a (k - 1)-permutation <x_1,...,x_k-1> followed by an additional element x_k. By induction, the probability of the k-permutation is (n - k - 1)!/n! * P(A[k] = x_k | A[1, k - 1] = <x1,...,x_k-1>). Since x_k is chosen at random from A[k, n] in the Knuth shuffle algorithm, the second factor is 1/(n - k + 1) which produces the final probability as (n - k - 1)!/n! * 1/(n - k + 1) = (n − k)!/n! and proves the lemma.
With the lemma proven and the knowledge that the Knuth shuffle generates any n-permutation before the (n + 1)st iteration, we can conclude by the lemma that the Knuth shuffle generates a random n-permutation with probability (n - (n + 1) + 1)!/n! = 0!/n! = 1/n!, concluding the proof.
(
Edited: 2022-03-14)
'''William Wang, Abhishek Reddy, Pradeep Narayana
'''
----
To prove that any n-permutation is equally likely to be generated by the Knuth shuffle, we first prove the lemma that prior to each i <= n, the subarray A[1, i - 1] contains each possible (i - 1)-permutation with probability (n - 1 + 1)!/n!. We do this by induction on i.
----
In the base case where i = 1, A[1, 0] is the empty array containing the 0-permutation with probability (n-1+1)!/n! = n!/n! = 1, which is true since there is exactly 1 0-permutation.
----
In the induction step, we assume that at i = k, the subarray A[1, k - 1] contains each possible (k - 1)-permutation with probability (n - k - 1)!/n!. A particular k-permutation is composed of a (k - 1)-permutation <x_1,...,x_k-1> followed by an additional element x_k. By induction, the probability of the k-permutation is (n - k - 1)!/n! * P(A[k] = x_k | A[1, k - 1] = <x1,...,x_k-1>). Since x_k is chosen at random from A[k, n] in the Knuth shuffle algorithm, the second factor is 1/(n - k + 1) which produces the final probability as (n - k - 1)!/n! * 1/(n - k + 1) = (n − k)!/n! and proves the lemma.
----
With the lemma proven and the knowledge that the Knuth shuffle generates any n-permutation before the (n + 1)st iteration, we can conclude by the lemma that the Knuth shuffle generates a random n-permutation with probability (n - (n + 1) + 1)!/n! = 0!/n! = 1/n!, concluding the proof.