← 回題庫

卷別

資料結構與演算法

選擇

國立臺灣大學 2026 · 考試 · 第 16 題

(4 points) Assume that there are KK possible keys {1,2,…,K}\{1, 2, \dots, K\} and mm hash table slots {0,1,…,m−1}\{0, 1, \dots, m-1\} with m>1m > 1. In double hashing, the probe sequence is

h(k,i)=(h1(k)+i h2(k)) mod m.h(k, i) = \big(h_1(k) + i\, h_2(k)\big) \bmod m.

For a fixed key kk, we want the sequence h(k,0),h(k,1),…h(k, 0), h(k, 1), \dots to visit all mm table slots before repeating, so that insertion succeeds whenever the table is not full. Which of the following conditions is necessary and sufficient for this property (for that key kk)?

  • (A)
    mm must be prime.
  • (B)
    h2(k)h_2(k) must be odd.
  • (C)
    gcd⁡(h2(k),m)=1\gcd(h_2(k), m) = 1.
  • (D)
    The first hash function h1h_1 must be injective (one-to-one) from {1,2,…,K}\{1, 2, \dots, K\} to {0,1,…,m−1}\{0, 1, \dots, m-1\}.
  • (E)
    None of the other choices.

標準解析

AI 已複查