diff --git a/docs/Chap05/Problems/5-1.md b/docs/Chap05/Problems/5-1.md index 1f818edceb..5835ef43b6 100755 --- a/docs/Chap05/Problems/5-1.md +++ b/docs/Chap05/Problems/5-1.md @@ -20,4 +20,18 @@ $$ \frac{n_{i + 1} - n_i}{n_{i + 1} - n_i} = 1. $$ -**b.** For this choice of $n_i$ , we have that at each increment operation, the probability that we change the value of the counter is $\frac{1}{100}$. Since this is a constant with respect to the current value of the counter $i$, we can view the final result as a binomial distribution with a $p$ value of $0.01$. Since the variance of a binomial distribution is $np(1 − p)$, and we have that each success is worth $100$ instead, the variance is going to be equal to $0.99n$. +**b.** For this choice of $n_i$ , we have that at each increment operation, the probability that we change the value of the counter is $\frac{1}{100}$. Since this is a constant with respect to the current value of the counter $i$, we can view the final result as a binomial distribution with a $p$ value of $0.01$. Since the variance of the counter value $C_n$ is given by the formula for a binomial distribution: + +$$ +\text{Var}(C_n) = np(1-p) = n \cdot 0.01 \cdot (1 - 0.01) = 0.0099n. +$$ + +The question asks for the variance of the value represented by the counter, let's call it $V_n$. The relationship is $V_n = 100 \cdot C_n$. + +Using the variance property $\text{Var}(aX) = a^2\text{Var}(X)$, we get: + +$$ +\text{Var}(V_n) = \text{Var}(100 \cdot C_n) = 100^2 \cdot \text{Var}(C_n) = 10000 \cdot (0.0099n) = 99n. +$$ + +So, the variance is going to be equal to $99n$. \ No newline at end of file diff --git a/docs/Chap05/Problems/5-2.md b/docs/Chap05/Problems/5-2.md index 1384df7332..164b52f60e 100755 --- a/docs/Chap05/Problems/5-2.md +++ b/docs/Chap05/Problems/5-2.md @@ -31,11 +31,10 @@ RANDOM-SEARCH(x, A, n) v = Ø // a set (or bitmap, etc.) of visited indices while |v| < n: i = RANDOM(1, n) - if i ∉ v: // only use i if it hasn't been picked before - if A[i] = x: - return i - else: - v = v ∪ {i} + if A[i] = x: + return i + if i ∉ v: + v = v ∪ {i} return NIL ```