Can you explain this code for me please? It's urgent and it doesn't need to be detailed. It's about directed acyclic graphs. inDegree = digraph. inDegree ();Queue queue = new LinkedList...


Can you explain this code for me please? It's urgent and it doesn't need to be detailed. It's about directed acyclic graphs.


public static boolean isDag (DirectedGraph digraph) {<br>Map<Integer, Integer> inDegree = digraph. inDegree ();<br>Queue<Integer> queue = new LinkedList<> ();<br>inDegree.forEach ( (key, value) -> {<br>if (value == 0)<br>queue. add (key);<br>});<br>int count<br>0;<br>while (!queue.isEmpty()) {<br>int node = queue.poll();<br>List<Integer> edges = digraph.adjList.get(node);<br>edges.forEach(edge -> {<br>inDegree.put(edge, inDegree.get(edge) - 1);<br>if (inDegree.get(edge)<br>queue.add (edge);<br>}<br>});<br>0) {<br>==<br>count++;<br>}<br>return count == inDegree.size();<br>}<br>

Extracted text: public static boolean isDag (DirectedGraph digraph) { Map inDegree = digraph. inDegree (); Queue queue = new LinkedList<> (); inDegree.forEach ( (key, value) -> { if (value == 0) queue. add (key); }); int count 0; while (!queue.isEmpty()) { int node = queue.poll(); List edges = digraph.adjList.get(node); edges.forEach(edge -> { inDegree.put(edge, inDegree.get(edge) - 1); if (inDegree.get(edge) queue.add (edge); } }); 0) { == count++; } return count == inDegree.size(); }

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here