Question: plz write a better pseudocode then explain Algorithm 2 RANDDISCRETE2(P) 1: F new n-element array 2: F[0] P[O] 3: for + 1 to n -

plz write a better pseudocode then explain

 plz write a better pseudocode then explain Algorithm 2 RANDDISCRETE2(P) 1:F new n-element array 2: F[0] P[O] 3: for + 1 to

Algorithm 2 RANDDISCRETE2(P) 1: F new n-element array 2: F[0] P[O] 3: for + 1 to n - 1 do 4: F[]+F[ j - 1] +PG] 5: r+ RANDO 6: r0 7: while r > Fu do 8: + +1 9: return (d) Write, in pseudocode, a linear-time algorithm RANDDISCRETE3 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!