← 回題庫

卷別

資料結構

選擇

國立中央大學 2026 · 考試 · 第 50 題

The following pseudo code is a simple algorithm to generate a permutation of n items. Please fill in the BLANK area in Line 6 with a correct formula such that i <= j < n

 1  function Uniform(m)
 2      return a random integer between 0 and m-1;
 3
 4  function Permutation(A,n)
 5      for i = 0 to n-2
 6          j=i+Uniform(____________)
 7          SWAP(A[i],A[j])
  • (A)
    n
  • (B)
    n-i
  • (C)
    i
  • (D)
    n-1
  • (E)
    n/2

標準解析

AI 生成