Question: Attached below is Lab 1 2 import java.io . * ; import java.util. * ; public class Distance { private static List bfsShortestPath ( Map
Attached below is Lab
"import java.io; import java.util.; public class Distance private static List bfsShortestPathMap graph, int source, int destination Queue queue new LinkedList; Map predecessors new HashMap; queue.addsource; predecessors.putsource null; while queue.isEmpty int current queue.poll; if current destination List path new LinkedList; for Integer at destination; at null; at predecessors.getat path.add at; return path; for int neighbor : graph.getOrDefaultcurrent Collections.emptyList if predecessors.containsKeyneighbor queue.addneighbor; predecessors.putneighbor current; return null; public static void mainString args Step : Parse the graph Map graph new HashMap; try Scanner scanner new Scannernew Filewebtxt; while scannerhasNextInt int src scanner.nextInt; int dst scanner.nextInt; graph.computeIfAbsentsrc k new ArrayListadddst; scanner.close; catch FileNotFoundException e System.err.printlnFile not found."; return; Step & : Handle user input and compute shortest paths Scanner input new ScannerSystemin; while true System.out.printEnter source and destination: ; int source input.nextInt; int destination input.nextInt; Terminate if negative integers are entered if source destination break; Find the shortest path using BFS List path bfsShortestPathgraph source, destination; if path null System.out.printlndestination is unreachable from source; else System.out.printlndistance pathsize; System.out.printpath ; for int node : path System.out.printnode ; System.out.println; input.close;
Answer this question please
"How many vertices are distance from vertex in the directed graph described in the file web.txt used in Lab
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
