Algorithm 1)
Step 1:Obtain a sample $y$ from distribution $Y$ and a sample $u$ from $(0,1)$
Step 2: Check whether or not $u < f(y)/ M.g(y)$
if true accept $y$ as a sample from $f$
Else, reject the value of $y$
return to the sampling step
Algorithm 2)
There are model parameters $\theta$ described by a prior $\pi(\theta)$, and a forwards-simulation model for the data $x$, defined by $\pi(x|\theta)$. It is clear that a simple algorithm for simulating from the desired posterior $\pi(\theta|x)$ can be obtained as follows. First simulate from the joint distribution $\pi(\theta,x)$ by simulating $\theta^\star\sim\pi(\theta)$ and then $x^\star\sim \pi(x|\theta^\star)$. This gives a sample $(\theta^\star,x^\star)$ from the joint distribution. A simple rejection algorithm which rejects the proposed pair unless $x^\star$ matches the true data $x$ clearly gives a sample from the required posterior distribution. https://darrenjw.wordpress.com/2013/03/31/introduction-to-approximate-bayesian-computation-abc/
- Sample $\theta^\star \sim \pi(\theta^\star)$
- Sample $x^\star\sim \pi(x^\star|\theta^\star)$
- If $x^\star=x$, keep $\theta^\star$ as a sample from $\pi(\theta|x)$, otherwise reject.
- Return to step 1