Java /* BFS.java Template for Breadth First Search This template includes some testing code to help verify
Fantastic news! We've Found the answer you've been seeking!
Question:
Java
/* BFS.java Template for Breadth First Search This template includes some testing code to help verify the implementation. To interactively provide test inputs, run the program with To conveniently test the algorithm with a large input, create a text file containing one or more test graphs (in the format described below) and run the program with java BFS file.txt where file.txt is replaced by the name of the text file which contains the graph. The input consists of a series of graphs in the following format: ... An input file can contain an unlimited number of graphs; each will be processed separately.*/import java.util.Scanner;import java.util.LinkedList; import java.util.Queue;import java.io.File;public class BFS { /* BFS(G) Given an adjacency matrix describing a undirected graph, print the listing of vertices encountered by a Queue based breadth-first search starting at vertex 0. */ public static void QueueBasedBFS(int[][] G) { int n = G.length; /* ... Your code here ... */ } /* main() Contains code to test the BFS method. */ public static void main(String[] args) { Scanner s; if (args.length > 0) { try{ s = new Scanner(new File(args[0])); } catch (java.io.FileNotFoundException e){ System.out.printf("Unable to open %s",args[0]); return; } System.out.printf("Reading input values from %s.",args[0]); }else { s = new Scanner(System.in); System.out.printf("Reading input values from stdin."); } int graphNum = 0; double totalTimeSeconds = 0; //Read graphs until EOF is encountered (or an error occurs) while(true) { graphNum++; if(graphNum != 1 && !s.hasNextInt()) break; System.out.printf("Reading graph %d",graphNum); int n = s.nextInt(); int[][] G = new int[n][n]; int valuesRead = 0; for (int i = 0; i 0)?totalTimeSeconds/graphNum:0); }}
graph1.txt
6
0 0 0 1 1 0
0 0 1 0 1 1
0 1 0 0 0 1
1 0 0 0 1 0
1 1 0 1 0 0
0 1 1 0 0 0
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date: