C++ DepthFirstSearch and BreadthFirstSearch The purpose of this lab is to do a depth first search an

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Order a Similar Paper Order a Different Paper

C++ DepthFirstSearch and BreadthFirstSearch The purpose of this lab is to do a depth first search and a breadth first search of a graph. The input to the program will be the number of nodes, the adjacency matrix, and the start node, which are also the parameters to the two functions depthfirst and breadthfirst. The output from your program will be the list of nodes visited in depth first order and a list of nodes visited in breadth first order. You MAY NOT use the standard template library. You MUST use ONLY arrays. There should be exactly 3 functions: main, depthfirst, and breadthfirst. The largest any graph can be is 10 nodes. The nodes will be numbered beginning with node 1 (keep that in mind when dealing with the C++ arrays). Hint #1: In both algorithms it is necessary to keep up with whether or not a no de has been visited. This can be done with a one dimensional int or boolean array that contains 10 slots. If the entry is 0, then the node hasnA????1t been visited. If it is a 1, then the node has been visited.

Hint #2: In the breadth-first search, it is necessary to manage a queue using an
array. Remember that an index in an array is an address for that array just like
a pointer is an address in memory. So you can have a queue array of length
10 and two int references (indices) head and tail which are used to index into the
array.

A sample run is as follows:
Please input the number of nodes: 5

Please input the adjacency matrix:
0 1 0 1 1
1 0 1 1 0
0 1 0 1 1
1 1 1 0 0
1 0 1 0 0

Please input the start node: 1

The depth first traversal of the graph is: 1 2 3 4 5

The breadth first traversal of the graph is: 1 2 4 5 3