Question: 1 8 . 1 Lab 1 6 : Graph BFS In this Lab we continue developing our Graph class by adding breadth - first search
Lab : Graph BFS
In this Lab we continue developing our Graph class by adding breadthfirst search BFS
Step : Setup
Copy your completed Graph class from Lab into the Graph java file below.
Copy your LinkedList class from Lab into the LinkedList. java file below. Recall that the LinkedList is used to store adjacent vertices at each vertex in the Graph.
Inspect the LabProgram, which allows you to test each method of Graph in Develop Mode as you write your code. Automatic testing in Submit mode requires completion of most methods of this lab.
Step : Complete the BFS method of the Graph class to implement breadthfirst search.
Follow the guidance given in the block comment for the method and class notes.
Step : Test the BFS method and updates
After finishing BFS the following methods will produce more results and will be tested more completely in both the LabProgram and unit testing:
testGetDistance
testGetParent
testGetColor Parallel Arrays for BFS
Your Graph will store information not only about adjacent vertices.
It will also store data about the color, parent and the distance from the source of all the vertices in the Graph for tracing the BFS algorithm and color, parent, discovery time, and finish time for the DFS algorithm.
Inside your Graph class, there are six private ArrayLists to store this data:
private ArrayList adj;
private ArrayList color;
private ArrayList distance;
private ArrayList parent;
private ArrayList discoverTime;
private ArrayList finishTime;
These ArrayLists are in parallel to each other. For example:
adj.get
color.get
distance.get
parent.get
These all store information about vertex of the Graph and are updated and used in the BFS method.
Performs breath first search on this Graph give a source vertex
@param source the starting vertex
@precondition source is a vertex in the graph
@throws IndexOutOfBoundsException when the source vertex is out of bounds
of the graph
public void BFSInteger source throws IndexOutOfBoundsException
Performs depth first search on this Graph in order of vertex lists
public void DFS
Private recursive helper method for DFS
@param vertex the vertex to visit
private void visitint vertex
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
