Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. (15 pts. A common operation in many computer simulations is the generation of samples from a discrete random variable. The problem essentially can be
4. (15 pts. A common operation in many computer simulations is the generation of samples from a discrete random variable. The problem essentially can be mathematically reduced to the following simple case. Consider a discrete random variable X taking values in the set Sx = {0, 1, 2, ..., n - 1} with probability mass function (PMF) Px, so that px () is the probability that the random variable X takes value = Sx. Let Fx be the cumulative distribution function (CDF) of X, whose domain is the set of real values R = (-0, too), and is defined as O, Fx(z) = P(X n-1. 11, A simple general approach to generate random samples from X according to its PMF px is to draw a number r uniformly at random from the interval (0,1), and then use the CDF FX to select the value x as the random sample of X if Fx (1 1) F(X) do 10: 2+ +1 11: return c Algorithm 2 RANDDISCRETE2(P) 1: F+ new n-element array 2: F[0] + P[O] 3: for j+ 1 to n - 1 do 4: F[j] + F[ j - 1] + P[j] 5: r + RANDO 6: 170 7: while r > Fu do 8: ++1 9: return (a) Give the tightest running-time and space characterization using big-Oh and big-Omega, or big-Theta, of RAND DISCRETE1 in terms of n. Briefly justify your answer. Time Space (b) Give the tightest running-time and space characterization using Big-Oh and Big-Omega, or Big-Theta, of RAND DISCRETE2 in terms of n. Briefly justify your answer. Time Space (c) Which algorithm do you recommend to implement, and why? Briefly justify your answer. (d) Write, in pseudocode, a linear-time algorithm RAND DISCRETE3 for this computational problem that takes an array P of n elements as input and outputs a random integer consistent with a discrete random variable with integer values 0, 1,..., n - 1 according to the probability mass function encoded by P and that uses a constant amount of space. Is this algorithm better than the algorithm you recommended to implement in the previous part of this problem? Please explain briefly. 4. (15 pts. A common operation in many computer simulations is the generation of samples from a discrete random variable. The problem essentially can be mathematically reduced to the following simple case. Consider a discrete random variable X taking values in the set Sx = {0, 1, 2, ..., n - 1} with probability mass function (PMF) Px, so that px () is the probability that the random variable X takes value = Sx. Let Fx be the cumulative distribution function (CDF) of X, whose domain is the set of real values R = (-0, too), and is defined as O, Fx(z) = P(X n-1. 11, A simple general approach to generate random samples from X according to its PMF px is to draw a number r uniformly at random from the interval (0,1), and then use the CDF FX to select the value x as the random sample of X if Fx (1 1) F(X) do 10: 2+ +1 11: return c Algorithm 2 RANDDISCRETE2(P) 1: F+ new n-element array 2: F[0] + P[O] 3: for j+ 1 to n - 1 do 4: F[j] + F[ j - 1] + P[j] 5: r + RANDO 6: 170 7: while r > Fu do 8: ++1 9: return (a) Give the tightest running-time and space characterization using big-Oh and big-Omega, or big-Theta, of RAND DISCRETE1 in terms of n. Briefly justify your answer. Time Space (b) Give the tightest running-time and space characterization using Big-Oh and Big-Omega, or Big-Theta, of RAND DISCRETE2 in terms of n. Briefly justify your answer. Time Space (c) Which algorithm do you recommend to implement, and why? Briefly justify your answer. (d) Write, in pseudocode, a linear-time algorithm RAND DISCRETE3 for this computational problem that takes an array P of n elements as input and outputs a random integer consistent with a discrete random variable with integer values 0, 1,..., n - 1 according to the probability mass function encoded by P and that uses a constant amount of space. Is this algorithm better than the algorithm you recommended to implement in the previous part of this problem? Please explain briefly
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started