Solution Found!
Consider two program segments:S1: while (B1) {printf(hey
Chapter 2, Problem 1(choose chapter or problem)
Consider two program segments:
\(\begin{array}{l}S_{1} \text{ : while } \left(B_{1}\right)\{\\
\text{printf ("hey you! } \backslash \mathbf{n} \text{ ");}\\
\text{printf ("finished } \backslash \mathrm{n} \text{ ') ;}\\
\text{\}}\end{array}\)
and
\(\begin{array}{l}
S_{2} \text { : if }\left(B_{2}\right) \\
\text { printf("'hey you! \n"'); } \\
\text { else } \\
\text { printf ("finished }(n \text { ")); } \\
\end{array}\)
Assuming that \(B_{1}\) is true with probability \(p_{1}\) and \(B_{2}\) is true with probability \(p_{2}\) , compute the pmf of the number of times “hey you!” is printed and compute the pmf of the number of times “finished” is printed by the following program:
\(\left\{S_{1} ; S_{2} ;\right\}\)
Questions & Answers
QUESTION:
Consider two program segments:
\(\begin{array}{l}S_{1} \text{ : while } \left(B_{1}\right)\{\\
\text{printf ("hey you! } \backslash \mathbf{n} \text{ ");}\\
\text{printf ("finished } \backslash \mathrm{n} \text{ ') ;}\\
\text{\}}\end{array}\)
and
\(\begin{array}{l}
S_{2} \text { : if }\left(B_{2}\right) \\
\text { printf("'hey you! \n"'); } \\
\text { else } \\
\text { printf ("finished }(n \text { ")); } \\
\end{array}\)
Assuming that \(B_{1}\) is true with probability \(p_{1}\) and \(B_{2}\) is true with probability \(p_{2}\) , compute the pmf of the number of times “hey you!” is printed and compute the pmf of the number of times “finished” is printed by the following program:
\(\left\{S_{1} ; S_{2} ;\right\}\)
ANSWER:Step 1 of 2
\(\mathrm{S}_{1}\) will continue to execute until \(\mathrm{B}_{1}\) is evaluated to false.
So, total number of times \(\mathrm{S}_{1}\) will execute will be
\(\mathrm{p}_{1}+\left(\mathrm{p}_{1}\right)^{2}+\left(\mathrm{p}_{1}\right)^{3}+\left(\mathrm{p}_{1}\right)^{4}+\ldots . . \text { till infinity }\)
Let k denote it, so
\(\mathrm{k}=\mathrm{p}_{1}+\left(\mathrm{p}_{1}\right)^{2}+\left(\mathrm{p}_{1}\right)^{3}+\left(\mathrm{p}_{1}\right)^{4}+\ldots . . \text { till infinity }\)
Each time will execute,” hey you”! and “finished” will be printed.