-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Labels
Description
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
- I would like to implement this algorithm myself
- I'm requesting this for someone else to implement
- I need help implementing this algorithm
Code of Conduct
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable