算法导论(3版)第5章
习题解答 by zevolo
5.2-3
indicator random variableset X(i) = I(i)
= 1 (when ith dot is show)
0 (when ith dot is hide)
Now E(X) = E(X(1)) + E(X(2)) + E(X(3)) + .... + E(X(6)) means how many expected dots can show
we get X(1) = 1 (all sides show 1st dot), X(2) = 5/6, X(3) = 4/6, ...
E(X) = P(X(1)) + P(X(2)) + ... + P(X(6))
= 7/2
5.3-7
proof: use loop invariant
assume result set has the element with equally likely always
1) it is easy to prove there is only one element.
2) assume the assumption is right for k < m, that is for m - 1 subset from the n - 1,
the probability is p = (m - 1) / (n - 1)
then for the every element i ( 1 <= i and i < n), the probability is
p(i) = p * 1 + (1 - p) * (1/n)
= m / n
for the element i (i = n) the probability is
p(n) = 1 / n + ((m - 1)/n)
= m / n
3) prove the last
5.4-1
1) the probability is
P(at least one who has same birthday with me) = 1 - P(no one has same birthday with me)
= 1 - P(B1) * P(B2|B1) * P(B3|B2&B1) * ... * P(Bk | B(k-1)&B(K-2)&...&B1) Bi means i is not same birthday with me
= 1 - P(B1) * p(B2) * P(B3) * ... * P(Bk) Bi is independency
= 1 - ((n-1)/n) ^ k
k = 253
2) the probability is
P = 1 - P(no one birthday is 1.1) - P(only one birthday is 1.1)
= 1 - ((n-1)/n) ^ k - sigma_1_k(P(i) * ((n-1)/n) ^ (k-1))
= 1 - ((n-1)/n) ^ k - sigma_1_k((1/n) * ((n-1)/n) ^ (k-1))
= 1 - ((n-1)/n) ^ k - (k/n) * ((n-1)/n) ^ (k-1)
k = 613
本文解析了《算法导论》第三版第五章中的几个关键习题,包括使用指示随机变量计算期望值的方法,通过循环不变量证明随机选择算法的正确性,以及计算至少一个人与自己生日相同的概率。
5065

被折叠的 条评论
为什么被折叠?



