← 回題庫

卷別

資料結構及演算法

計算

國立政治大學 2026 · 考試 · 第 13 題

Consider a hash table of size M=20M = 20 (slots indexed from 0 to 19). The primary hash function is defined as: h1(k)=k mod 20h_1(k) = k \bmod 20. The secondary hash function is defined as: h2(k)=(k mod 7)+1h_2(k) = (k \bmod 7) + 1. Assume the hash table is initially empty before each part of the question. We will insert the following sequence of keys SS in the order given:

S=[8,38,3,5,28,18,65,83,25]S = [8, 38, 3, 5, 28, 18, 65, 83, 25]

(a) (5%) Assuming we use double hashing for collision resolution, determine the final structure of the hash table after all keys in SS have been inserted. Note: The probe sequence is given by:

h(k,i)=(h1(k)+i⋅h2(k)) mod Mh(k, i) = (h_1(k) + i \cdot h_2(k)) \bmod M

where ii is the probe number.

(b) (5%) If we search for 48, what is the total number of probes made during the search?

(c) (10%) Suppose we are given nn keys, mm hash table slots, and two uniform hash functions hah_a and hbh_b. Further suppose hashing scheme uses hah_a for the odd keys and hbh_b for the even keys. What is the expected number of keys in a slot?

標準解析

AI 已複查