Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task below: --------------------------------------------------------------------------------------------------------- test.java: package dsf_matrix_forStudents; /* * class: Test */ public class Test { public static void main(String[] args) { Graph theGraph = new

Task below:image text in transcribedimage text in transcribedimage text in transcribed

---------------------------------------------------------------------------------------------------------

test.java:

package dsf_matrix_forStudents; /* * class: Test */

public class Test { public static void main(String[] args) { Graph theGraph = new Graph(); theGraph.addVertex('A'); // 0 (start for dfs) theGraph.addVertex('B'); // 1 theGraph.addVertex('C'); // 2 theGraph.addVertex('D'); // 3 theGraph.addVertex('E'); // 4 theGraph.addVertex('F'); // 4

theGraph.addEdge(0, 1); // AB theGraph.addEdge(0, 2); // AC theGraph.addEdge(1, 3); // BD theGraph.addEdge(2, 4); // CE theGraph.addEdge(2, 3); // CD theGraph.addEdge(0, 3); // AD theGraph.addEdge(3, 4); // DE theGraph.addEdge(3, 5); // DE

System.out.print("Stack based dfs visits:----------------------- "); theGraph.dfs(); System.out.println(); System.out.print("recursive dfs visits:----------------------- "); theGraph.recusive_dfs(0); } // end main() } // end class DFSApp

---------------------------------------------------------------------------------------------------------

stack.java:

package dsf_matrix_forStudents; /* * class: Stack */

class Stack { private final int SIZE = 50; private int[] st; private int top; //constructor public Stack() { st = new int[SIZE]; // make array top = -1; } // put item on stack public void push(int j) { st[++top] = j; } //take item off stack public int pop() { return st[top--]; } //peek at top of stack public int peek() { return st[top]; } //true if nothing on stack public boolean isEmpty() { return (top == -1); }

} // end class Stack

---------------------------------------------------------------------------------------------------------

graph.java:

package dsf_matrix_forStudents; /* * class: Graph */

class Graph { private final int MAX_VERTS = 20; private Vertex vertexList[]; // list of vertices private int adjMatrix[][]; // adjacency matrix private int nVerts; // current number of vertices private Stack theStack; //------------------------------------------------------------ public Graph() // constructor { vertexList = new Vertex[MAX_VERTS]; // adjacency matrix adjMatrix = new int[MAX_VERTS][MAX_VERTS]; nVerts = 0; for(int y=0; y

/* * depth-first search: Recursive */ public void recusive_dfs(int start) { //TO-DO } // end depthFirstSearch

} // end class Graph ////////////////////////////////////////////////////////////////

class Vertex { public char data; // data public boolean isVisited;

public Vertex(char d) // constructor { data = d; isVisited = false; }

} // end class Vertex

Adjacency matrix for Graph (a) 1 4 5 6 7 8 Q R S T W X Y Z 0 P 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 2 R 0 0 0 0 0 0 1 0 0 3 0 0 0 0 1 0 0 0 0 4 T 0 0 0 0 0 1 0 0 0 5 W 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 7 Y 0 1 0 0 0 0 1 z 0 0 0 0 0 0 0 0 0 a) A directed graph and b) its adjacency matrix 14 A-3

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

LO4 Identify a system for controlling absenteeism.

Answered: 1 week ago