算法导论第五章学习笔记
来源:互联网 发布:sql count 求和 编辑:程序博客网 时间:2024/06/13 03:39
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 variableI{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.
• Lemma⇒E [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 .
- 算法导论第五章学习笔记
- 《算法导论》学习笔记 第四章&&第五章
- 《算法导论》第一章~第五章 要点笔记
- 算法导论: 第五章
- 算法导论第五章
- 算法导论学习笔记-第五章-概率分析和随机算法
- 算法导论 学习笔记 第五章 概率分析和随机化算法
- 算法导论第五章总结
- 算法导论读书笔记 第五章
- 《算法导论》学习笔记
- 《算法导论》学习笔记
- 算法导论学习笔记
- 《算法导论》学习笔记
- 算法导论第二章学习笔记
- 算法导论第四章学习笔记
- 算法导论第七章学习笔记
- 算法导论学习笔记---第三章
- 算法导论--第六章学习笔记
- 不是自己的事情不要问, 别人的事情不要管
- Spring自动装配模式五:autodetect的解析
- hibernate-memcached--在Hibernate中使用Memcached作为一个二级分布式缓存
- Spring自动装配模式二:byName的解析
- 有理想的程序员必须知道的15件事
- 算法导论第五章学习笔记
- Jquery表单验证插件–Validform:一行代码搞定整站的
- Spring自动装配模式三:byType的解析
- silverlight反射代码,需要用到
- aspx页面上传递参数给Silverlight插件的方法
- 项目管理实践【六】自动同步数据库
- Spring自动装配模式四:constructor的解析
- IFC --- An introduction to Freescale Integrated Flash Controller
- 内核通知链 学习笔记