算法导论(3版)第5章少量习题的解答

本文解析了《算法导论》第三版第五章中的几个关键习题,包括使用指示随机变量计算期望值的方法,通过循环不变量证明随机选择算法的正确性,以及计算至少一个人与自己生日相同的概率。

算法导论(3版)第5章

习题解答  by zevolo

5.2-3

indicator random variable
set 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


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值