Question
Can you help with the following? I did an implementation of graphs which implemented a DFS (Depth First Search algorithm) and the minimum spanning tree
Can you help with the following? I did an implementation of graphs which implemented a DFS (Depth First Search algorithm) and the minimum spanning tree (MST) for the vertices in a graph. Now I need to implement in Graph.JAVA the BFS (Breadth First Search) for the vertices using a Queue. I want to implement this as a function inside the same Graph.java like the one that is done for DFS below. I want to also add the main to test the BFS by using the same graph used for testing the DFS. Then I implemented the DFS in the graph using a Stack. I want to implement the DFS in the same program using recursion without a Stack. I can use the same main to test. I can use the same graph example that is used for testing the BFS above. class StackX{ private final int size = 20; private int[] st; private int top; public StackX(){ st = new int[size]; top =-1; } public void push(int j){ st[++top] = j; } public int pop(){ return st[top--]; } public int peek(){ return st[top]; } public boolean isEmpty(){ return (top==-1); } } class Vertex{ public char label; public boolean wasVisited; public Vertex(char lbl){ label = lbl; wasVisited = false; } } public class Graph { private final int MAX_VERTS = 20; // MAximumm number of vertices. private Vertex vrtxLst[]; //Vertex List private int adjMat[][];//Adjacency Matrix private int nVerts; //current number of vertices private StackX stck; public Graph(){ vrtxLst = new Vertex[MAX_VERTS]; adjMat = new int[MAX_VERTS][MAX_VERTS]; nVerts = 0; for( int j=0; j
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