CS/SE 3341 Last Name: First Name: The Midterm Examination - SOLUTIONS • There are five problems on this exam. You need to solve any four and indicate which problem you skip. If no problem is clearly marked as skipped, only the first four problems will be graded. • Problem skipped: • Each problem = 20 points. Total points = 80. Time = 1 hour 15 minutes. • Show your work. No points will be given if the appropriate work is not shown, even if the answer is correct. • A formula sheet and table of distributions are attached at the end of this exam. • Take a deep breath and relax. 1. Suppose that 10% of inmates in a large prison are known to be innocent. A non-profit group randomly selects 20 inmates from this prison. Find the probability the group will find at least 3 innocent inmates. SOLUTION. This is P (X ≥ 3), where X is the number of innocent inmates, out of 20. This is a number of successes in n = 20 Bernoulli trials with the probability of success p = 0.10. Thus, X is Binomial(n = 20, p = 0.10), and from the Table of Binomial distribution, P (X ≥ 3) = 1 − F (2) = 1 − 0.677 = 0.323 . 2. Suppose that there are two websites, A and B, for renting books. The site A receives 60% of all orders. Among the orders placed on site A, 75% arrive on time. Among the orders placed on site B, 90% arrive on time. Given that an order arrived on time, find the probability that the order was placed on site B. SOLUTION. Denote the events, A = the order is placed on web site A B = the order is placed on web site B T = the order is received on time Given: P (A) = 0.6, P (B) = 0.4, P (T |A) = 0.75, P (T |B) = 0.9. By the Bayes Rule, P (B|T ) = = P (T |B)P (B) P (T |B)P (B) = P (T ) P (T |A)P (A) + P (T |B)P (B) 4 (0.9)(0.4) 0.36 = = or 0.4444 , (0.75)(0.6) + (0.9)(0.4) 0.45 + 0.36 9 where the Law of Total Probability was used to compute P (T ). 3. Let random variable X denote the time (in years) it takes to develop a software. Suppose that X has the following probability density function: x if 0 ≤ x ≤ 2, 2 f (x) = 0 otherwise. (a) Compute the probability that it takes more than 6 months to develop the software. (b) Compute the expected number of years it takes to develop a software. SOLUTION. ∫ (b) E(X) = 2 f (x)dx = (a) P (X > 1/2 years ) = 1/2 ∫ ∫ ∞ ∫ 2 xf (x)dx = 0 1/2 x=2 x 1 x2 15 =1− dx = = or 0.9375. 2 4 x=1/2 16 16 x=2 x2 x3 8 4 = −0= dx = or 1.3333 years 2 6 x=0 6 3 4. Let X and Y be the number of interceptions made by the host and visiting teams in a football game. The joint probability mass function of X and Y is given in the table, P (x, y) 0 y 1 2 x 0 1 2 0.36 0.14 0.10 0.14 0.10 0.02 0.10 0.02 0.02 (a) Are X and Y independent? Justify your answer. (b) Find E(Y ). (c) Let Z = XY . Find the probability mass function of Z. SOLUTION. (a) X and Y are independent if P (x, y) = PX (x)PY (y) for all x and y. Compute the marginal pmf of X by adding the joint pmf P (x, y) over all values of y, PX (0) = 0.36 + 0.14 + 0.10 = 0.60, PX (1) = 0.26, PX (2) = 0.14. Compute the marginal pmf of Y by adding the joint pmf P (x, y) over all values of x, PY (0) = 0.36 + 0.14 + 0.10 = 0.60, PY (1) = 0.26, PY (2) = 0.14. Now, X and Y are not independent because, for example, P (1, 1) = 0.10 is not equal to PX (1)PY (1) = (0.26)(0.26) = 0.0676. (b) E(Y ) = 2 ∑ yPY (y) = (0)(0.60) + (1)(0.26) + (2)(0.14) = 0.54 y=0 (c) When X = 0, 1, 2 and Y = 0, 1, 2, their product Z = XY takes values 0, 1, 2, and 4. It remains to find the probability of each value of Z, z 0 1 2 4 PZ (z) 0.36 + 0.14 + 0.10 + 0.14 + 0.10 = 0.84 0.10 0.02 + 0.02 = 0.04 0.02 5. Suppose that the time it takes to get service in a restaurant follows a gamma distribution with mean 8 minutes and standard deviation 4 minutes. (a) Find the parameters r and λ of the gamma distribution. (b) You went to this restaurant at 6:30. What is the probability that you will receive service before 6:36? SOLUTION. (a) For this Gamma distribution of X, we have E(X) = r =8 λ and r Std(X) = √ = 4. λ Find parameters by solving these two equations for r and λ, Std(X) √ = λ = 1/2 E(X) ⇒ λ = 1/4 , r = 8λ = 2 (b) Using the Gamma-Poisson formula with a Gamma(r = 2, λ = 1/4) variable X and a Poisson(λx = 1/4 · 6 = 1.5) variable Y , we get P (X < 6 minutes) = P (Y ≥ r) = P (Y ≥ 2) = 1 − F (1) = 1 − 0.558 = 0.442 , from the Poisson distribution table with parameter 1.5. CS/SE 3341 Last Name: First Name: The Midterm Examination - SOLUTIONS • There are five problems in this exam. You need to solve any four and indicate which problem you skip. If no problem is clearly marked as skipped, only the first four problems will be graded. • Problem skipped: • Each problem = 20 points. Total points = 80. Time = 1 hour 15 minutes. • Show your work. No points will be given if the appropriate work is not shown, even if the answer is correct. • A formula sheet and table of distributions are attached at the end of this exam. • Take a deep breath and relax. 1. During a severe thunderstorm, any transmission line is damaged with probability 0.04, independently of other transmission lines. A city with 75 transmission lines is hit by a severe thunderstorm. What is the probability that at least 5 of them get damaged? SOLUTION. This is P (X ≥ 5), where X is the number of damaged transmission lines, out of 75. This is a number of successes in n = 75 Bernoulli trials with the probability of success p = 0.04. Thus, X is Binomial(n = 75, p = 0.04), large n and small p, so X is approximately Poisson with parameter λ = np = (75)(0.04) = 3. From the table of Poisson distribution, P (X ≥ 5) = 1 − F (4) = 1 − 0.815 = 0.185 . 2. Each computer in a lab has a 15% chance to be infected with a virus. If a computer is infected, an antivirus software finds the virus with probability 0.9. If a computer is not infected, the software will still generate a false alarm and report a virus with probability 0.10. If the antivirus software reports a virus, what is the probability that indeed, the computer is infected? SOLUTION. Denote the events, I = computer is infected R = the software reports a virus ¯ = 0.85, P (R|I) = 0.9, P (R|I) ¯ = 0.1. Given: P (I) = 0.15, P (I) By the Bayes Rule, P (I|R) = = P (R|I)P (I) P (R|I)P (I) = ¯ (I) ¯ P (R) P (R|I)P (I) + P (R|I)P 27 (0.9)(0.15) 0.135 = = or 0.6136 , (0.9)(0.15) + (0.1)(0.85) 0.135 + 0.085 44 where the Law of Total Probability was used to compute P (R). 3. Consider a computer that has two operating systems installed on it. Let X and Y denote the number of times the computer freezes in a day when it runs on the first and the second operating systems, respectively. P (x, y) 0 x 1 2 y 0 1 2 0.50 0.05 0.12 0.10 0.07 0.01 0.08 0.06 0.01 (a) Are X and Y independent? Justify your answer. (b) Find E(X). (c) Let Z = XY , which is the product of X and Y . Find the probability mass function of Z. SOLUTION. (a) X and Y are independent if P (x, y) = PX (x)PY (y) for all x and y. Compute the marginal pmf of X by adding the joint pmf P (x, y) over all values of y, PX (0) = 0.50 + 0.05 + 0.12 = 0.67, PX (1) = 0.18, PX (2) = 0.15. Compute the marginal pmf of Y by adding the joint pmf P (x, y) over all values of x, PY (0) = 0.50 + 0.10 + 0.08 = 0.68, PY (1) = 0.18, PY (2) = 0.14. Now, X and Y are not independent because, for example, P (0, 0) = 0.50 is not equal to PX (0)PY (0) = (0.67)(0.68) = 0.4556. (b) E(X) = 2 ∑ xPX (x) = (0)(0.67) + (1)(0.18) + (2)(0.15) = 0.48 x=0 (c) When X = 0, 1, 2 and Y = 0, 1, 2, their product Z = XY takes values 0, 1, 2, and 4. It remains to find the probability of each value of Z, z 0 1 2 4 PZ (z) 0.50 + 0.10 + 0.08 + 0.05 + 0.12 = 0.85 0.07 0.06 + 0.01 = 0.07 0.01 4. Let random variable X denote the time (in years) it takes to develop a software. Suppose that X has the following probability density function: 4 if 0 ≤ x ≤ 1, 5x f (x) = 0 otherwise. (a) Compute the probability that it takes more than 3 months to develop the software. (b) Compute the expected number of years it takes to develop a software. SOLUTION. ∫ (a) P (X > 1/4 years ) = (b) E(X) = 1 4 f (x)dx = 1/4 ∫ ∫ ∞ ∫ 1 0 ( )5 1 1023 = 1− = or 0.9990. 4 1024 x=1 5 5x6 5 5x dx = = −0 = or 0.8333 years or 10 months 6 x=0 6 6 5 xf (x)dx = 5x dx = 1/4 x=1 x5 x=1/4 5. Two programmers started working on their computer programs at 9:00 am. The first programmer will take a Uniform(a = 1 hr, b = 4 hrs) time to finish the program. The second programmer will need a Gamma(r = 5, λ = 1 hrs−1 ) time. Which programmer has a better chance to finish before 11:00 am? SOLUTION. We need to compute P (X < 2) and P (Y < 2) for a Uniform(a = 1 hr, b = 4 hrs) variable X and a Gamma(r = 5, λ = 1 hrs−1 ) variable Y and compare them. For the Uniform distribution with density f (x) = ∫ ∫ 2 P (X < 2) = f (x)dx = −∞ 1 2 1 4−1 = 1/3 for 1 < x < 4, 1 dx = (1)(1/3) = 1/3 or 0.3333 4−1 For the second programmer, use the Gamma-Poisson formula with a Gamma(r = 5, λ = 1) variable Y and a Poisson(λx = 1 · 2 = 2) variable Z, P (Y < 2) = P (Z ≥ r) = P (Z ≥ 5) = 1 − F (4) = 1 − 0.947 = 0.053 , from the Poisson distribution table with parameter 2. Thus, the first programmer has a better chance to finish before 11:00 am. Cheat Sheet for the Midterm Exam Rules of Probability P (B|A)P (A) P (B) Bayes Rule P (A|B) = Total Probability P (A) = P (A|B)P (B) + P (A|B̄)P (B̄) n ∑ P (A|Bj )P (Bj ) P (A) = j=1 Discrete Distributions ( ) n P (x) = px (1 − p)n−x for x = 0, 1, ..., n, x ( ) n! n where = x x!(n − x)! Binomial probability mass function Geometric probability mass function P (x) = (1 − p)x−1 p for x = 1, 2, ... e−λ λx for x = 0, 1, ... x! Poisson probability mass function P (x) = Poisson approximation Binomial(n, p) ≈ Poisson(λ = np) for n ≥ 30, p ≤ 0.05 Continuous Distributions Exponential density f (x) = λe−λx for 0 < x < ∞ Uniform density f (x) = Gamma-Poisson formula P (X < x) = P (Y ≥ r) 1 for a < x < b b−a for X ∼ Gamma(r, λ), Y ∼ Poisson(λx) Distribution Bernoulli (p) Binomial (n, p) Geometric (p) Poisson (λ) Exponential (λ) Gamma (r, λ) Uniform (a, b) E(X) p np 1 p λ 1 λ r λ a+b 2 Var(X) p(1 − p) np(1 − p) 1−p p2 λ 1 λ2 r λ2 (b − a)2 12 Binomial Cumulative Distribution Function p n x .05 .10 .15 .20 .25 .30 .35 .40 .45 .50 .55 .60 .65 .70 .75 .80 .85 .90 .95 5 0 1 2 3 4 .774 .977 .999 1.0 1.0 .590 .919 .991 1.0 1.0 .444 .835 .973 .998 1.0 .328 .737 .942 .993 1.0 .237 .633 .896 .984 .999 .168 .528 .837 .969 .998 .116 .428 .765 .946 .995 .078 .337 .683 .913 .990 .050 .256 .593 .869 .982 .031 .188 .500 .813 .969 .018 .131 .407 .744 .950 .010 .087 .317 .663 .922 .005 .054 .235 .572 .884 .002 .031 .163 .472 .832 .001 .016 .104 .367 .763 .000 .007 .058 .263 .672 .000 .002 .027 .165 .556 .000 .000 .009 .081 .410 .000 .000 .001 .023 .226 10 0 1 2 3 4 5 6 7 8 .599 .914 .988 .999 1.0 1.0 1.0 1.0 1.0 .349 .736 .930 .987 .998 1.0 1.0 1.0 1.0 .197 .544 .820 .950 .990 .999 1.0 1.0 1.0 .107 .376 .678 .879 .967 .994 .999 1.0 1.0 .056 .244 .526 .776 .922 .980 .996 1.0 1.0 .028 .149 .383 .650 .850 .953 .989 .998 1.0 .013 .086 .262 .514 .751 .905 .974 .995 .999 .006 .046 .167 .382 .633 .834 .945 .988 .998 .003 .023 .100 .266 .504 .738 .898 .973 .995 .001 .011 .055 .172 .377 .623 .828 .945 .989 .000 .005 .027 .102 .262 .496 .734 .900 .977 .000 .002 .012 .055 .166 .367 .618 .833 .954 .000 .001 .005 .026 .095 .249 .486 .738 .914 .000 .000 .002 .011 .047 .150 .350 .617 .851 .000 .000 .000 .004 .020 .078 .224 .474 .756 .000 .000 .000 .001 .006 .033 .121 .322 .624 .000 .000 .000 .000 .001 .010 .050 .180 .456 .000 .000 .000 .000 .000 .002 .013 .070 .264 .000 .000 .000 .000 .000 .000 .001 .012 .086 15 0 1 2 3 4 5 6 7 8 9 10 11 .463 .829 .964 .995 .999 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .206 .549 .816 .944 .987 .998 1.0 1.0 1.0 1.0 1.0 1.0 .087 .319 .604 .823 .938 .983 .996 .999 1.0 1.0 1.0 1.0 .035 .167 .398 .648 .836 .939 .982 .996 .999 1.0 1.0 1.0 .013 .080 .236 .461 .686 .852 .943 .983 .996 .999 1.0 1.0 .005 .035 .127 .297 .515 .722 .869 .950 .985 .996 .999 1.0 .002 .014 .062 .173 .352 .564 .755 .887 .958 .988 .997 1.0 .000 .005 .027 .091 .217 .403 .610 .787 .905 .966 .991 .998 .000 .002 .011 .042 .120 .261 .452 .654 .818 .923 .975 .994 .000 .000 .004 .018 .059 .151 .304 .500 .696 .849 .941 .982 .000 .000 .001 .006 .025 .077 .182 .346 .548 .739 .880 .958 .000 .000 .000 .002 .009 .034 .095 .213 .390 .597 .783 .909 .000 .000 .000 .000 .003 .012 .042 .113 .245 .436 .648 .827 .000 .000 .000 .000 .001 .004 .015 .050 .131 .278 .485 .703 .000 .000 .000 .000 .000 .001 .004 .017 .057 .148 .314 .539 .000 .000 .000 .000 .000 .000 .001 .004 .018 .061 .164 .352 .000 .000 .000 .000 .000 .000 .000 .001 .004 .017 .062 .177 .000 .000 .000 .000 .000 .000 .000 .000 .000 .002 .013 .056 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .001 .005 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 .736 .925 .984 .997 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .392 .677 .867 .957 .989 .998 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .176 .405 .648 .830 .933 .978 .994 .999 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .069 .206 .411 .630 .804 .913 .968 .990 .997 .999 1.0 1.0 1.0 1.0 1.0 .024 .091 .225 .415 .617 .786 .898 .959 .986 .996 .999 1.0 1.0 1.0 1.0 .008 .035 .107 .238 .416 .608 .772 .887 .952 .983 .995 .999 1.0 1.0 1.0 .002 .012 .044 .118 .245 .417 .601 .762 .878 .947 .980 .994 .998 1.0 1.0 .001 .004 .016 .051 .126 .250 .416 .596 .755 .872 .943 .979 .994 .998 1.0 .000 .001 .005 .019 .055 .130 .252 .414 .591 .751 .869 .942 .979 .994 .998 .000 .000 .001 .006 .021 .058 .132 .252 .412 .588 .748 .868 .942 .979 .994 .000 .000 .000 .002 .006 .021 .058 .131 .249 .409 .586 .748 .870 .945 .981 .000 .000 .000 .000 .002 .006 .021 .057 .128 .245 .404 .584 .750 .874 .949 .000 .000 .000 .000 .000 .002 .006 .020 .053 .122 .238 .399 .583 .755 .882 .000 .000 .000 .000 .000 .000 .001 .005 .017 .048 .113 .228 .392 .584 .762 .000 .000 .000 .000 .000 .000 .000 .001 .004 .014 .041 .102 .214 .383 .585 .000 .000 .000 .000 .000 .000 .000 .000 .001 .003 .010 .032 .087 .196 .370 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .001 .006 .022 .067 .170 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .002 .011 .043 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .003 Poisson Cumulative Distribution Function x 0 1 2 3 4 5 0.1 .905 .995 1.00 1.00 1.00 1.00 0.2 .819 .982 .999 1.00 1.00 1.00 0.3 .741 .963 .996 1.00 1.00 1.00 0.4 .670 .938 .992 .999 1.00 1.00 0.5 .607 .910 .986 .998 1.00 1.00 0.6 .549 .878 .977 .997 1.00 1.00 0.7 .497 .844 .966 .994 .999 1.00 λ 0.8 .449 .809 .953 .991 .999 1.00 0.9 .407 .772 .937 .987 .998 1.00 1.0 .368 .736 .920 .981 .996 .999 1.1 .333 .699 .900 .974 .995 .999 1.2 .301 .663 .879 .966 .992 .998 1.3 .273 .627 .857 .957 .989 .998 1.4 .247 .592 .833 .946 .986 .997 1.5 .223 .558 .809 .934 .981 .996 x 0 1 2 3 4 1.6 .202 .525 .783 .921 .976 1.7 .183 .493 .757 .907 .970 1.8 .165 .463 .731 .891 .964 1.9 .150 .434 .704 .875 .956 2.0 .135 .406 .677 .857 .947 2.1 .122 .380 .650 .839 .938 2.2 .111 .355 .623 .819 .928 λ 2.3 .100 .331 .596 .799 .916 2.4 .091 .308 .570 .779 .904 2.5 .082 .287 .544 .758 .891 2.6 .074 .267 .518 .736 .877 2.7 .067 .249 .494 .714 .863 2.8 .061 .231 .469 .692 .848 2.9 .055 .215 .446 .670 .832 3.0 .050 .199 .423 .647 .815 5 6 7 8 9 .994 .999 1.00 1.00 1.00 .992 .998 1.00 1.00 1.00 .990 .997 .999 1.00 1.00 .987 .997 .999 1.00 1.00 .983 .995 .999 1.00 1.00 .980 .994 .999 1.00 1.00 .975 .993 .998 1.00 1.00 .970 .991 .997 .999 1.00 .964 .988 .997 .999 1.00 .958 .986 .996 .999 1.00 .951 .983 .995 .999 1.00 .943 .979 .993 .998 .999 .935 .976 .992 .998 .999 .926 .971 .990 .997 .999 .916 .966 .988 .996 .999