We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bb3541d commit 170bbf1Copy full SHA for 170bbf1
src/main/java/com/williamfiset/algorithms/graphtheory/Kahns.java
@@ -15,6 +15,11 @@
15
16
public class Kahns {
17
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.
23
public int[] kahns(List<List<Integer>> g) {
24
int n = g.size();
25
Stack<Integer> nodesWithNoIncomingEdges = new Stack<>();
0 commit comments