Topological Sorting And Autograd

Firms love to force candidates to go through bizarre humiliation rituals during interviews. One of these was to implement a topsort algo for their autograd engine. If we consider a computation graph where each node represents a variable and each edge represents a dependency, the goal of this algorithm is to sort the nodes in “ topological order ”, i.e. such that if there is an edge from node \(u\)…