← 回題庫

卷別

資料結構與演算法

選擇

國立臺灣大學 2025 · 考試 · 第 11 題

(5 points) Let SS be a collection of nn objects, each with a unique integer key ai∈{0,1,2,…,n2−1}a_i \in \{0, 1, 2, \dots, n^2 - 1\}. Consider hashing all the objects in SS into an array A[0…m−1]A[0 \dots m-1] of size m=⌈n1.5⌉m = \lceil n^{1.5} \rceil buckets. Each bucket stores a (singly) linked list of all objects hashed into the same bucket. The hashing algorithm works as follows. The algorithm first picks a hash function hh uniformly at random from a hash family H\mathcal{H}. Then, for each object i∈Si \in S, the algorithm computes h(ai)h(a_i) and inserts the object into the bucket A[h(ai)]A[h(a_i)]. The number of collisions τ\tau is defined to be the total number of (unordered) object pairs hashed into the same bucket. We focus on the choice of the hash family H\mathcal{H} and the worst-case expected number of collisions E[τ]\mathbb{E}[\tau]. Note that the term worst-case refers to the choice of the input set SS. Select all statement(s) that are correct for every sufficiently large nn.

  • (A)
    If H\mathcal{H} is a uniform hash family, then E[τ]=O(n)\mathbb{E}[\tau] = O(\sqrt{n}).
  • (B)
    If H\mathcal{H} is a universal hash family, then E[τ]=O(n)\mathbb{E}[\tau] = O(\sqrt{n}).
  • (C)
    If H={h(x)=(ax+b) mod m∣a,b∈Z and 0≤a,b≤m−1}\mathcal{H} = \{h(x) = (ax + b) \bmod m \mid a, b \in \mathbb{Z} \text{ and } 0 \le a, b \le m-1\}, then E[τ]=O(n)\mathbb{E}[\tau] = O(\sqrt{n}).
  • (D)
    If H={h(x)=(x2+x+c) mod m∣c∈Z and 0≤c≤m−1}\mathcal{H} = \{h(x) = (x^2 + x + c) \bmod m \mid c \in \mathbb{Z} \text{ and } 0 \le c \le m-1\}, then E[τ]=O(n)\mathbb{E}[\tau] = O(\sqrt{n}).
  • (E)
    The hash family described in (C) is a universal hash family.

標準解析

AI 已複查