Algorithm Name
Kahn's Algorithm
Programming Language
C++
Category
Graph Algorithms
Difficulty Level
Medium (Intermediate)
Algorithm Description
Kahn’s Algorithm works by:
- Finding all nodes with indegree = 0 (no incoming edges).
- Adding them to a queue.
- Removing one node at a time from the queue, adding it to the topological order, and reducing the indegree of its neighbors.
- If a neighbor’s indegree becomes 0, push it into the queue.
- Continue until the queue is empty.
If all nodes are processed → valid topological order.
If not → the graph has a cycle (not a DAG).
References (Optional)
https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/
https://cp-algorithms.com/graph/topological-sort.html
Contribution Intent
Code of Conduct
Algorithm Name
Kahn's Algorithm
Programming Language
C++
Category
Graph Algorithms
Difficulty Level
Medium (Intermediate)
Algorithm Description
Kahn’s Algorithm works by:
If all nodes are processed → valid topological order.
If not → the graph has a cycle (not a DAG).
References (Optional)
https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/
https://cp-algorithms.com/graph/topological-sort.html
Contribution Intent
Code of Conduct