Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program called BFS.cpp that implements the Breadth-First Search (BFS) algorithm . Your program should read an input file name and a starting

Write a C++ program called BFS.cpp that implements the Breadth-First Search (BFS) algorithm. Your program should read an input file name and a starting node from a user. After that, your program should display the list of vertices visited. In the problem, you can assume that the number of vertices in the input file is less than or equal to 25.

[Hint: Since the maximum number of vertices is less than or equal to 25, you can use a simple array-based queue for the BFS algorithm.]

Input file format: This is a sample input file called t1.txt.

image text in transcribed

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, t1.txt describes a graph like below:

image text in transcribed

One blank space is used to delimiter the data. Note that theres no blank space at the end of each line. If your program does not read the file properly, your program will get no credit.

The following presents a sample run of the program. Your program has to run exactly like this.

Enter filename:

Enter a start vertex: 0

BFS order: 0 -> 1 -> 2

In the program, your program has to follow our convention (= ascending order).

This is another sample input file called t2.txt.

image text in transcribed

This is a sample run:

Enter filename: C:\\tmp\\t2.txt

Enter a start vertex: 0

BFS order: 0 -> 2 -> 1 -> 3 -> 4

0 1 0 1 0 1 o 1 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions