Can someone help me with the below question. I'm stuck on part d. I understand with the rejection method I have to use a known density g(x) along with my f(x). What do I use for my g(x). I'm confused where to begin

Consider the (triangular) probability density function defined as

f(x) = 4x; 0 <= x <= 1/2

4 - 4x; 1/2 <= x <= 1

(a) Draw plots of the density and of the CDF.

(b) Use the Inverse CDF method to analytically find a function G(u) that transforms

random numbers from U(0; 1) distribution into random numbers from f(x).

(c) Use part (b) to generate 1000 data points from f(x) and plot their histogram.

(d) Use rejection sampling to generate 1000 data points from f(x) and plot their histogram.

What instrumental distribution and envelope did you use?

(e) Use the Monte Carlo method to estimate E[X2] when X is drawn from the distribution

with density f and compare your estimate to the actual value. You may use the data

generated in (c) or (d) for your estimation.