Autograd - pseudo Algorithm, how does DAG work in this?

My question is around what is the pseudo algorithm used by autograd to calculate the gradients? I understand that the inputs are leafs and outputs are roots - but wanted a more concrete discussion and solution on what is the pseudo algorithm.