Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions