When a joint distribution can be factored into a series of conditional probabilities, we can generate samples using ancestral sampling. the basic idea is to generate a sample from the root variable(s) and then sample from the subsequent conditional distributions based on this instantiation.
Consider a joint distribution over three variables, which (in this particular case) factors as:
To sample from this joint distribution, we first draw a sample from . Then we draw a sample from . Finally, we draw a sample from .