Question: Discrete distribution. Design a fast algorithm to repeatedly generate numbers from the discrete distribution: Given an array (mathrm{a}[]) of non-negative real numbers that sum to
Discrete distribution. Design a fast algorithm to repeatedly generate numbers from the discrete distribution: Given an array \(\mathrm{a}[]\) of non-negative real numbers that sum to 1 , the goal is to return index \(i\) with probability a \([i]\). Form an array sum [] of cumulated sums such that sum [i] is the sum of the first \(i\) elements of \(a[]\). Now, generate a random real number \(r\) between 0 and 1 , and use binary search to return the index \(i\) for which sum \([i] \leq r<\operatorname{sum}[i+1]\). Compare the performance of this approach with the approach taken in RandomSurfer (Program 1.6.2).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
