Explanation

- **Topological Sort** is used to order the vertices of a **directed acyclic graph (DAG)** such that for every directed edge `(u, v)`, vertex `u` appears before `v`.

-

  • Steps:

    • Find all vertices with no incoming edges (in-degree of 0) and add them to a queue.
    • Repeatedly remove a vertex from the queue, add it to the topological order, and reduce the in-degree of its neighbors.
    • Repeat until all vertices are processed.
  • Time Complexity:

    • O(V + E), where V is the number of vertices and E is the number of edges.