跳到主要内容

東京大学 情報理工学系研究科 創造情報学専攻 2008年8月実施 筆記試験 第1問

Author

itsuitsuki

Description (English)

Given nn records r1,r2,,rnr_1, r_2, \dots, r_n, each has a key k1,k2,,knk_1, k_2, \dots, k_n, respectively. Given a key, consider searching for the corresponding record. For a given query key vv, if there is a key kjk_j where v=kjv = k_j (1jn1 \le j \le n) then the search is successful and the record rjr_j is returned, otherwise the search fails and the failure is returned.

Let pjp_j be the probability where the query key vv is kjk_j, and pmissp_{\text{miss}} be the probability of the search failure. The computation time is almost proportional to the number of comparisons with vv. Let us calculate the average number of comparisons C\overline{C} and the maximum number of comparisons CmaxC_{\text{max}}.

(1) Consider a sequential search that compares vv with keys from k1k_1 to knk_n. (a) Obtain C\overline{C} and CmaxC_{\text{max}} when p1=p2==pn=12n,pmiss=12p_1 = p_2 = \dots = p_n = \frac{1}{2n}, p_{\text{miss}} = \frac{1}{2}. (b) Prove that C2\overline{C} \le 2 when p1=12,p2=14,,pn=12n,pmiss=12np_1 = \frac{1}{2}, p_2 = \frac{1}{4}, \dots, p_n = \frac{1}{2^n}, p_{\text{miss}} = \frac{1}{2^n}.

(2) Consider a binary search after sorting the keys. Let n=2m1n = 2^m - 1 (mm is a natural number), and moreover, one comparison will determine whether v<kj,v=kjv < k_j, v = k_j or v>kjv > k_j. (a) Obtain C\overline{C} and CmaxC_{\text{max}} for each case of m=1,2,3,4m=1, 2, 3, 4, when p1=p2==pn=pmissp_1 = p_2 = \dots = p_n = p_{\text{miss}}. (b) Obtain C\overline{C} and CmaxC_{\text{max}} as a function of mm when p1=p2==pn=pmissp_1 = p_2 = \dots = p_n = p_{\text{miss}}.

(3) Consider a search using a hash table. The records r1,,r8r_1, \dots, r_8 are inserted into the hash table of size S=17S = 17 using the hash function h(x)=xmodSh(x) = x \bmod S. Let the key values each be k1=10,k2=1,k3=17,k4=97,k5=21,k6=4,k7=39,k8=73k_1 = 10, k_2 = 1, k_3 = 17, k_4 = 97, k_5 = 21, k_6 = 4, k_7 = 39, k_8 = 73. (a) Draw the structure of the hash table by choosing an appropriate method for avoiding collision. (b) Obtain C\overline{C} and CmaxC_{\text{max}} when p1=p2==p8,pmiss=0p_1 = p_2 = \dots = p_8, p_{\text{miss}} = 0.

(4) Describe in general the advantages and disadvantages of sequential search, binary search and search using a hash table.