Problem

Approach

In DFS, we print a vertex and then recessively call it’s adjacent vertex. In topo sort we need to print adjacent vertex before the vertex

When a node is visited only after all it’s dependencies are visited

  • Should be directed acyclic graph for it to work
  • Used to list the steps of a process, like the ingredients nodes are pointing to pan node so we know first all ingredients are listed before lighting the pan.

Recursive and non recursive solution

Time Complexity
Auxiliary Space

My Code

Code Answer