Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ program called BFS.cpp that implements the Breadth-First Search (BFS) algorithm. Your progranm should read an input file name and a starting node
Write a C++ program called BFS.cpp that implements the Breadth-First Search (BFS) algorithm. Your progranm should read an input file name and a starting node from a user. After that, your program should display the list of nodes visited. In the problem, you can assume that the number of vertices in the input file is less than or equal to 25. Input file format: This is a sample input file called tl.txt. 3 0 1 0 The first line (= 3 in the example) indicates that there are three vertices in the graph. For the homework, we can assume that the first vertex starts from the number 0. Thus, tl.txt describes a graph like below One blank space is used to delimiter the data. Note that there's no blank space at the end of each line. If your program does not read the file properly, your program will get no credit. This is a sample result of the C++ progranm $ g++ o BFS BFS.cpp $ . /BFS Enter filename: tl.txt Enter a start vertex: 0 BFS order: 0 ->1 -> 2 program has to follow our convention (ascending order) This is another sample input file called t2.txt. 001 0 0 001 0 0 1 10 11 001 0 0 001 0 0 This is a sample run: $ g ++ -o BFS BFS.cpp Enter filename: t2.txt Enter a start vertex: 0 BFS order: 0 ->2->1-3 -> 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started