Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Artificial Intelligence A Modern Approach

Authors: Stuart J. Russell and Peter Norvig

2nd Edition

8120323823, 9788120323827, 978-0137903955

More Books

Students also viewed these Programming questions

Question

whats the result of 9 * 1 0

Answered: 1 week ago