Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Breadth First Search ( c++ programming )

Breadth First Search ( c++ programming )

Breadth First Search ( c++ programming )

Question Description

Breadth First Search

Introduction

Create a graph data structure using an adjacency list. The graph is undirected and unweighted. Then implement the Breadth First Search (BFS) Traversal on the graph. Use the Breadth First Search Traversal to find the shortest distance between the given source node and all other nodes in the graph.

Objective

You are given a header file, Graph.hpp, that defines what data member is in the Graph class. It also defines what functions you need to implement.

The main idea is to create a graph data structure using an adjacency list. And then implement two functionalities of Breadth First Traversal on the graph.

Complete the implementation of this class, adding public/private member variables and functions as needed. Your code is tested in the provided main.cpp.

You are given one private data member to implement the graph data structure:

vector<vector<int>> adjacency_list

Using this is mandatory.

You are given the implementation of one function:

● Graph() {} – default constructor

You will need to implement the following functions:

● Graph(int) – one argument constructor to create adjacency_list of Graph with a given number of vertices

● void addEdge(int, int) – add a new edge to the graph connecting vertex v1 to v2; Edge also needs to be added from v2 to v1

● vector<int> BFS() – Implement Breadth First Search algorithm, using an STL queue. Using an STL queue is mandatory. For additional features, vectors may be used. The function returns the vertices that will be traversed in BFS order. These vertices are returned in a vector. Assume BFS begins at vertex 0. Hint: Please refer to Breadth First Search Traversal slides on Titanium in Topics section. Please refer to Slide 5: Please convert the pseudocode to C++ code.

● vector<int> BFS_Shortest_Distance(int) – Find Shortest Distance from given source

vertex to all vertices in the graph. Use BFS to find this shortest distance. Using an STL

queue is mandatory. For additional features, vectors may be used. The function returns

the shortest distance from the source vertex to each vertex in the graph. These shortest

distances are returned in a vector.

Hint: Please refer to Breadth First Search Traversal slides on Titanium in Topics section.

Please refer to Slide 8: Please convert the pseudocode to C++ code. Adding a few lines

of code to the vector<int> BFS() function will give you this function.

● void print_graph() – You can write this function to see if you have created a correct

graph. This is optional. It can be helpful for debugging.

Source Code Files

You are given “starter” code files with declarations that may be incomplete and without any

implementation. Implement the code and ensure that all the tests in main.cpp pass

successfully.

● Graph.hpp: This is to be completed

● main.cpp: The main function tests the output of your functions. You may wish to add

additional tests. During grading your main.cpp file will be replaced with the one you were

provided with.

Obtaining and submitting code

Click the project link to obtain your own copy of the starter code and download it to your PC.

Testing (either of the two below)

1. On Tuffix:

Use the following command to compile your program:

clang++ -g -std=c++14 main.cpp -o test

To attempt to run the compiled test program, use the following command:

./test

2. You can use Visual Studio:

Free download: Community 2019

https://visualstudio.microsoft.com/downloads/

You can write, debug, run your project in Visual Studio.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20