Convert a PDF to a CDF
UberData Scientist · Technical ScreenLast updated
This question evaluates understanding of probability theory, numerical methods, and algorithmic implementation for converting probability density functions into cumulative distribution functions, addressing analytic versus sampled PDFs along with support, normalization, and monotonicity requirements.
Given a continuous random variable X with probability density function f(x), write code or describe an algorithm to construct its cumulative distribution function F(x) = P(X <= x). Handle both cases where the PDF is given in closed form and where it is available only as sampled (x, f(x)) points. Explain how you would deal with finite or infinite support, piecewise PDFs, numerical integration, normalization, and how to guarantee that the returned CDF is non-decreasing and approaches 0 and 1 at the boundaries.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.