Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/Chap05/Problems/5-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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$.
9 changes: 4 additions & 5 deletions docs/Chap05/Problems/5-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down