-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Louis1992
committed
Jun 21, 2015
1 parent
56701f8
commit 4aae037
Showing
6 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
C05-Probabilistic-Analysis-and-Randomized-Algorithms/5.1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
### Exercises 5.1-1 | ||
*** | ||
Show that the assumption that we are always able to determine which candidate is best in line 4 of procedure HIRE-ASSISTANT implies that we know a total order on the ranks of the candidates. | ||
|
||
### `Answer` | ||
**always**这个词表示对所有n!种组合,都能够确定,而这n!种组合已经囊括了所有的两两比较. | ||
|
||
|
||
### Exercises 5.1-2 | ||
*** | ||
Describe an implementation of the procedure RANDOM(a, b) that only makes calls to RANDOM(0, 1). What is the expected running time of your procedure, as a function of a and b? | ||
|
||
### `Answer` | ||
|
||
RANDOM(a,b): | ||
if(a == b) | ||
return a | ||
mid = (a+b)/2 | ||
r = RANDOM(0,1) | ||
if(r == 0) | ||
return RANDOM(a,mid) | ||
else | ||
return RANDOM(mid+1,b) | ||
running time O(lg(b-a)) | ||
|
||
### Exercises 5.1-3 | ||
*** | ||
Suppose that you want to output 0 with probability 1/2 and 1 with probability 1/2. At your disposal is a procedure BIASED-RANDOM, that outputs either 0 or 1. It outputs 1 with some probability p and 0 with probability 1 - p, where 0 < p < 1, but you do not know what p is. Give an algorithm that uses BIASED-RANDOM as a subroutine, and returns an unbiased answer, returning 0 with probability 1/2 and 1 with probability 1/2. What is the expected running time of your algorithm as a function of p? | ||
|
||
### `Answer` | ||
while true: | ||
x = BIASED-RANDOM() | ||
y = BIASED-RANDOM() | ||
if x != y: | ||
return x | ||
expected running time = 1/(2p(1-p)) | ||
|
||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
52 changes: 52 additions & 0 deletions
52
C05-Probabilistic-Analysis-and-Randomized-Algorithms/5.2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
### Exercises 5.2-1 | ||
*** | ||
In HIRE-ASSISTANT, assuming that the candidates are presented in a random order, what is the probability that you will hire exactly one time? What is the probability that you will hire exactly n times? | ||
|
||
### `Answer` | ||
分别是1/n和1/n! | ||
|
||
|
||
### Exercises 5.2-2 | ||
*** | ||
In HIRE-ASSISTANT, assuming that the candidates are presented in a random order, what is the probability that you will hire exactly twice? | ||
|
||
### `Answer` | ||
如果第一个雇员的质量是k,那么质量高于k的雇员都必须在质量最高的雇员后面. | ||
|
||
假设有n个雇员,质量分别是1,2,...,n.当第一个质量为k时,只雇佣2次的概率p = 1/(n-k).因为有n-k个质量比k高的,而且必须要最高的那个在前.而第一个质量为k的概率是1/n.所以 | ||
|
||
 | ||
|
||
### Exercises 5.2-3 | ||
*** | ||
Use indicator random variables to compute the expected value of the sum of n dice. | ||
|
||
### `Answer` | ||
Expectation of a single die | ||
|
||
 = \\frac{1+2+3+4+5+6}{6} = 3.5 ) | ||
|
||
Expectation of N dies | ||
|
||
 = \\sum_{i = 1}^{n} E\(X_i\) = 3.5n ) | ||
|
||
### Exercises 5.2-4 | ||
*** | ||
Use indicator random variables to solve the following problem, which is known as the **hat- check problem**. Each of n customers gives a hat to a hat-check person at a restaurant. The hat- check person gives the hats back to the customers in a random order. What is the expected number of customers that get back their own hat? | ||
|
||
### `Answer` | ||
每个人都是1/n的期望,所以总的是1 | ||
|
||
### Exercises 5.2-5 | ||
*** | ||
Let A[1...n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. (See Problem 2-4 for more on inversions.) Suppose that each element of A is chosen randomly, independently, and uniformly from the range 1 through n. Use indicator random variables to compute the expected number of inversions. | ||
|
||
### `Answer` | ||
最简单的解法如下: | ||
|
||
因为概率是一样的,所以出现正序和逆序是等量的,总共有n(n-1)/2对,所以期望是n(n-1)/4对. | ||
|
||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
61 changes: 61 additions & 0 deletions
61
C05-Probabilistic-Analysis-and-Randomized-Algorithms/5.3.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
C05-Probabilistic-Analysis-and-Randomized-Algorithms/5.4.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
C05-Probabilistic-Analysis-and-Randomized-Algorithms/problem.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters