注:本章内容需要一定的《概率论与随机过程》课程基础。
思考题
5-1 (概率计数)
a.
E[Xj] = o(1 - 1/(ni+1-ni)) + 1 · ((ni+1-ni) · 1/(ni+1-ni))=1
nE[Xj] = n
b.
Var[Xj] = E[Xj2] - E2[Xj] = 99
nVar[Xj] = 99n
5-2 (查找一个无序数组)
a.
解:
RANDOM-SEARCH(A, n, x)
let B(n)=0 be a new array
index = RANDOM(1, n)
while A[index] != x
B[index] = 1
if B.sum = n
return NIL
index = RANDOM(1, n)
return index
b.
解:n
c.
解:n/k
d.
解:n(lnn + O(1))
e.
解:(n+1)/2;n
f.
解:(n+1)/(k+1);n-k+1
g.
解:n;n
h.
解:与DETERMINISTIC-SEARCH相同。
i.
解:SCRAMBLE-SEARCH;因为可避免特殊输入情况带来的影响 ;DETERMINISTIC-SEARCH,因为SCRAMBLE-SEARCH虽然可以有更好的期望结果,但重新排列数组的操作时间内已经可以扫描一遍数组了。。