Skip to content

[REQUEST] Add Kahn's Algorithm in CPP #222

@anubhootipandey

Description

@anubhootipandey

Algorithm Name

Kahn's Algorithm

Programming Language

C++

Category

Graph Algorithms

Difficulty Level

Medium (Intermediate)

Algorithm Description

Kahn’s Algorithm works by:

  1. Finding all nodes with indegree = 0 (no incoming edges).
  2. Adding them to a queue.
  3. Removing one node at a time from the queue, adding it to the topological order, and reducing the indegree of its neighbors.
  4. If a neighbor’s indegree becomes 0, push it into the queue.
  5. 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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions