算法导论第五章学习笔记

概率分析与随机算法

Probabilistic analysis

We must use knowledge of, or make assumptionsabout, the distribution of inputs.

  • The expectation is over this distribution.
  • This technique requires that we can make a reasonable characterization of the input distribution.
  • The expectation is taken over the distribution of the possible inputs. Thus we are, in effect, averaging the running time over all possible inputs.

Randomized algorithms

What makes an algorithm randomized: An algorithm is randomized if its behavior is determined in part by values produced by a random-number generator.

Indicator random variables

-------A simple yet powerful technique for computing the expected value of a random

variable.

Definition

Suppose we are given a sample space S and an event A. Then the indicator random variable I{A} associated with event A is defined as

Lemma

For an event A, let XA = I {A}. Then E [XA] = Pr {A}.

Proof Letting be the complement of A, we have

E [XA] = E [I {A}]

= 1 · Pr {A} + 0 · Pr {} (definition of expected value)

= Pr {A} .

Example:Determine the expected number of heads in n coin ßips.

Let X be a random variable for the number of heads in n ßips.Could compute .

   

For i = 1, 2, . . . , n, define Xi = I {the i th flip results in event H}.

Then .

Lemma says that E[Xi ] = Pr {H} = 1/2 for i = 1, 2, . . . , n.

Expected number of heads is .

Problem: We want .We have only the individual expectations E [X1] , E [X2] , . . . , E [Xn].

Solution: Linearity of expectation says that the expectation of the sum equals

the sum of the expectations. Thus,

Note: Indicator random variables greatly simplify the calculation. So it is used throughout Introduction to Algorithms .

Analysis of the hiring problem

Assume that the candidates arrive in a random order.Let X be a random variable that equals the number of times we hire a new office assistant.

Define indicator random variables X1, X2, . . . , Xn, where Xi = I {candidate i is hired} .

Useful properties:

X = X1 + X2 +· · ·+ Xn.

LemmaE [Xi ] = Pr {candidate i is hired}.

We need to compute Pr {candidate i is hired}.Candidate i is hired if and only if candidate i is better than each of candidates1, 2, . . . , i − 1.

   

Assumption that the candidates arrive in random order

candidates 1, 2, . . . , iarrive in random order

any one of these first i candidates is equally likely tobe the best one so far.

Thus, Pr {candidate i is the best so far} = 1/i .Which implies E[Xi ] = 1/i .

Thus, the expected hiring cost is , which is much better than the worst case cost of .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值