edited by
128 views
0 votes
0 votes

In the following pseudocode, assume that for any pair of integers $x \leq y$, the function random ( $\mathrm{x}, \mathrm{y})$ produces an integer uniformly chosen from the set $\{x, x+1, \ldots, y\}$.

n=9
for (i=1 to n){
A[i]=i
}
for (i=1 to n){
r= random (i, n)
temp =A[i]
A [i]= A [r]
A[r]=temp
print A[i]
}


Which of the following statements is TRUE of the output of the code?

  1. It outputs all permutations of $123456789$ with equal probability.
  2. It never outputs $123456789$.
  3. It outputs all cyclic permutations of $123456789$ with equal probability, and does not print any other output.
  4. The output is always $987654321$.
  5. The output may not be a permutation of $123456789$.

     

edited by

Please log in or register to answer this question.

Answer:

Related questions

223
views
1 answers
0 votes
admin asked Jan 13
223 views
Let $\text{S}$ be the set of all $4$ -digit numbers created using just the digits $1,2,3,4,5$ such that no two successive digits are the same. If the numbers in $\text{S}...
210
views
1 answers
0 votes
admin asked Jan 13
210 views
For any positive integer $\text{N}$, let $\text{p(N)}$ be the probability that a uniformly random number $a \in\{1, \ldots, N\}$ has an odd number of factors (including 1...
185
views
1 answers
0 votes
admin asked Jan 13
185 views
For two languages $\text{A, B}$ over the alphabet $\Sigma$, let the perfect shuffle of $\text{A}$ and $\text{B}$ be the language\begin{Bmatrix}w=a_1 b_1 a_2 b_2 \cdots a_...
136
views
0 answers
0 votes
admin asked Jan 13
136 views
The four nucleotides in $\text{DNA}$ are called $\text{A, C, G}$, and $\text{T}$. Consider the following languages over the alphabet $\{\mathrm{A}, \mathrm{C}, \mathrm{G}...