Skip to content

Commit 170bbf1

Browse files
William FisetWilliam Fiset
William Fiset
authored and
William Fiset
committed
Kahn's algorithm description
1 parent bb3541d commit 170bbf1

File tree

1 file changed

+5
-0
lines changed
  • src/main/java/com/williamfiset/algorithms/graphtheory

1 file changed

+5
-0
lines changed

src/main/java/com/williamfiset/algorithms/graphtheory/Kahns.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
public class Kahns {
1717

18+
// Kahn's algorithm finds a topological ordering by iteratively removing nodes
19+
// in the graph which have no incoming edges. When a node is removed from the
20+
// graph, it is added to the topological ordering and all its edges are
21+
// removed allowing for the next set of nodes with no incoming edges to be
22+
// selected.
1823
public int[] kahns(List<List<Integer>> g) {
1924
int n = g.size();
2025
Stack<Integer> nodesWithNoIncomingEdges = new Stack<>();

0 commit comments

Comments
 (0)